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

Elmar HInz elmar.hinz at team.MINUS.red.DOT.net
Thu Mar 8 10:16:03 CET 2007


 > 
> 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


Hi Ries,

there are several possible ways and what you write looks quite OK for
me. I can imagine that you will find some or other better trick by time,
but you got started and you experienced the basic principles.

It is right to do as few as possible in the controller. It should mainly
controll the chain of workwflow of the different objects.

Regards

Elmar


















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