[TYPO3-ect] MVC and image rendering...

R. van Twisk typo3 at rvt.dds.nl
Wed Mar 7 13:58:11 CET 2007


R. van Twisk wrote:
> hey Guys,
>
>
> since I am not to the whole MVC thing I have a question.
>
> It's about image rendering... Now I could render the image in my model,
> where I go over my array anyways....
>
> But actually it should be done in my view, right?
>
> If so, does it mean I need to pick up teh array from
> my view again in some function and render images.
> Or is it fine if I render images in my model?
>
> I am trying to find a efficient solution.... On the other hand teh array 
> is small
> and will stay below 18 images orso..
>
>
> Ries
>
>   

To answer myself I think I found a better way to do it
that looks more like what phpView does. What I do
is basically assign a object view to smarty in he render function like this:

    function render($view){
          
        if(!$this->available) return 'smarty is not available';

        $this->smarty->assign($this -> getArrayCopy()); 
        $this->smarty->assign_by_ref('view', $this); 
       
        return $this->smarty->display($this->pathToTemplates . '/' . $view);
    }

Then in my view I create a function for image rendering,
it looks like this:

    function renderImage($image, $configKey, $titleText='', $altText='') {
        $TSconf = $this -> getConfiguration($configKey.'.');
        $cObj = $this -> findCObject();

        // Check if teh file exists on the FS
        $pInfo = pathinfo ( $image );   
        if (is_file(PATH_site.$this->conf['uploadFolder'].$image)) {
            $image_file_name = $this->conf['uploadFolder'].$image;
            }
        else {               
            $image_file_name = $this->conf['noImage'];
        }           
        $cObj -> data['tmpfile'] = $image_file_name;
        $TSconf['titleText'] = $titleText;
        $TSconf['altText'] = $altText;
           
        // Try to render the image in it's origional state as supported 
my IM
        // IF GIFBUILDER was enable for this image config
        if ($TSconf['file.']['format'] && $TSconf['file'] == 'GIFBUILDER') {
            $off = strtolower($pInfo['extension']);
            switch (strtolower($pInfo['extension'])) {
                case 'gif':
                    $TSconf['file.']['format'] = 'gif';
                    break;
                case 'png':
                    $TSconf['file.']['format'] = 'png';
                    break;
                default:
                    $TSconf['file.']['format'] = 'jpg';
            }
        }
        return $cObj -> IMAGE($TSconf);

    }



So now I can call the above function from smarty doing it like this:


{section name=item loop=$exhibitionItems}
    {$view->renderImage($exhibitionItems[item].objectspath, 'image', 
$exhibitionItems[item].title, $exhibitionItems[item].short_description)}
{/section}

It's not a true OO approach yet but I feel it's better then my first method.
Now all rendering is happening in the view rather then my controller
executing the 'render images' code.

in a true OO approach I would like to see something like this:

{section name=item loop=$exhibitionItems}
    {$exhibitionItems[item].title.render()}<br />
    {$exhibitionItems[item].objectspath.render()}
{/section}


I need to see if the above is possible using the current setup,
and see if it makes sense at all in a scripting language like PHP.


Ries





More information about the TYPO3-team-extension-coordination mailing list