Changeset 5940


Ignore:
Timestamp:
01/15/12 19:36:06 (4 months ago)
Author:
vain
Message:
  • added $this->view->render($viewdata, $template)
  • on simple templates, this will save one assign() cmd in the module
  • closes ticket #255
Location:
trunk/core/renderer
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/renderer/csv.renderer.php

    r4766 r5940  
    5353{ 
    5454    private $data = array(); 
    55     private $header = array();    
     55    private $header = array(); 
    5656 
    5757    public function initializeEngine() 
     
    6666 
    6767    /** 
    68      * @param string $filepath location of where the csv file should be saved 
     68     * @param string $template The filepath location of where to save the csv file. 
     69     * @param array|object viewdata 
    6970     */ 
    70     public function render($filepath) 
     71    public function render($template, $viewdata) 
    7172    { 
    72  
    73         $this->mssafe_csv($filepath, $this->data, $this->header); 
     73        $this->data = $viewdata; 
     74        $this->mssafe_csv($template, $this->data, $this->header); 
    7475    } 
    7576 
     
    102103    private function mssafe_csv($filepath, $data, $header = array()) 
    103104    { 
    104         if($fp = fopen($filepath, 'w')) 
     105        $fp = fopen($filepath, 'w'); 
     106 
     107        if($fp === true) 
    105108        { 
    106109            $show_header = true; 
  • trunk/core/renderer/php.renderer.php

    r5812 r5940  
    107107        if(is_object($key)) 
    108108        { 
     109            # @todo pull object props to array 
    109110            $this->data[$key] = $value->fetch(); 
    110111        } 
     
    128129     * @return string HTML Representation of Template with Vars 
    129130     */ 
    130     public function render() 
     131    public function render($template, $viewdata) 
    131132    { 
    132         return $this->fetch(); 
     133        $this->assign($viewdata); 
     134 
     135        return $this->fetch($template); 
    133136    } 
    134137 
  • trunk/core/renderer/phptal.renderer.php

    r5811 r5940  
    9898     * Add data to the PHPTAL view 
    9999     * 
    100      * @param mixed $tpl_parameter 
    101      * @param mixed $value 
    102      */ 
    103     public function assign($tpl_parameter, $value) 
     100     * @param mixed $tpl_parameter The placeholder. 
     101     * @param mixed $value The value. 
     102     */ 
     103    public function assign($tpl_parameter, $value = null) 
    104104    { 
    105105        if(is_array($tpl_parameter)) 
     
    112112        else 
    113113        { 
    114             $this->renderer->$param = $val; 
    115         } 
    116     } 
    117  
    118     /* 
     114            if ($tpl_parameter != null) 
     115            { 
     116                $this->renderer->$tpl_parameter = $value; 
     117            } 
     118        } 
     119    } 
     120 
    119121    public function setTemplate($template) 
    120122    { 
    121123        $this->renderer->setTemplate($template); 
    122     }*/ 
     124    } 
    123125 
    124126    /** 
     
    168170    } 
    169171 
    170     /** 
    171      * Set PHPTAL variables 
    172      * 
    173      * @param string $key variable name 
    174      * @param string $value variable value 
    175      */ 
    176     public function __set($key, $value) 
    177     { 
    178         $this->renderer->assign($key, $value); 
    179     } 
    180  
    181     /** 
    182      * Get PHPTAL Variable Value 
    183      * 
    184      * @param string $key variable name 
    185      * @return mixed variable value 
    186      */ 
    187     public function __get($key) 
    188     { 
    189         return $this->renderer->$key; 
    190     } 
    191  
    192     /** 
    193      * Check if PHPTAL variable is set 
    194      * 
    195      * @param string $key variable name 
    196      */ 
    197     public function __isset($key) 
    198     { 
    199         return isset($this->renderer->$key); 
    200     } 
    201  
    202     /** 
    203      * Unset PHPTAL variable 
    204      * 
    205      * @param string $key variable name 
    206      */ 
    207     public function __unset($key) 
    208     { 
    209         if (isset($this->renderer->$key)) 
    210         { 
    211             unset($this->renderer->$key); 
    212         } 
    213     } 
    214  
    215     /** 
    216      * Clone PHPTAL object 
    217      * 
    218      * @todo Check if clone is needed to work with several instances of phptal for widgets? 
    219      */ 
    220     /* 
    221     public function __clone() 
    222     { 
    223         $this->phptal = clone $this->phptal; 
    224     } 
    225     */ 
    226172 
    227173    /** 
     
    247193            $output = $this->renderer->execute(); 
    248194 
     195            # return or echo the content 
    249196            if ($returnContent === true) 
    250197            { 
     
    256203            } 
    257204        } 
    258         catch (Clansuite_Exception $e) 
     205        catch (Exception $e) 
    259206        { 
    260207            throw new Clansuite_Exception($e); 
     
    302249        return $this->renderer->setCacheLifetime($lifetime); 
    303250    } 
     251    /** 
     252     * Set PHPTAL variables 
     253     * 
     254     * @param string $key variable name 
     255     * @param string $value variable value 
     256     */ 
     257    public function __set($key, $value) 
     258    { 
     259        $this->renderer->assign($key, $value); 
     260    } 
     261 
     262    /** 
     263     * Get PHPTAL Variable Value 
     264     * 
     265     * @param string $key variable name 
     266     * @return mixed variable value 
     267     */ 
     268    public function __get($key) 
     269    { 
     270        return $this->renderer->$key; 
     271    } 
     272 
     273    /** 
     274     * Check if PHPTAL variable is set 
     275     * 
     276     * @param string $key variable name 
     277     */ 
     278    public function __isset($key) 
     279    { 
     280        return isset($this->renderer->$key); 
     281    } 
     282 
     283    /** 
     284     * Unset PHPTAL variable 
     285     * 
     286     * @param string $key variable name 
     287     */ 
     288    public function __unset($key) 
     289    { 
     290        if (isset($this->renderer->$key)) 
     291        { 
     292            unset($this->renderer->$key); 
     293        } 
     294    } 
     295 
     296    /** 
     297     * Clone PHPTAL object 
     298     * 
     299     * @todo Check if clone is needed to work with several instances of phptal for widgets? 
     300     */ 
     301    /* 
     302    public function __clone() 
     303    { 
     304        $this->phptal = clone $this->phptal; 
     305    } 
     306    */ 
    304307} 
    305308?> 
  • trunk/core/renderer/renderer.base.php

    r5810 r5940  
    7878 
    7979    /** 
     80     * @var array|object Viewdata 
     81     */ 
     82    public $viewdata = null; 
     83 
     84    /** 
    8085     * Construct Renderer 
    8186     * 
     
    110115     * Renders the given Template with renderMode wrapped (with Layout) 
    111116     * 
    112      * @return string 
    113      */ 
    114     abstract public function render($template); 
     117     * @param string Template 
     118     * @param array|object Data to assign to the template. 
     119     * @return string 
     120     */ 
     121    abstract public function render($template, $viewdata); 
    115122 
    116123    /** 
  • trunk/core/renderer/serialized.renderer.php

    r4738 r5940  
    5454    /** 
    5555     * Render serialized PHP data 
     56     *  
     57     * @param $template Unused. 
     58     * @param $viewdata Data to serialize. 
     59     * 
     60     * @return string Serialized data. 
    5661     */ 
    57     public function render($data) 
     62    public function render($template, $viewdata) 
    5863    { 
    59         return serialize($this->data); 
     64        return serialize($this->viewdata); 
    6065    } 
    6166} 
  • trunk/core/renderer/smarty.renderer.php

    r5893 r5940  
    7070 
    7171        # debug display of all smarty related directories 
    72         #$this->renderer->testInstall(); 
     72        # $this->renderer->testInstall(); 
    7373    } 
    7474 
    7575    /** 
    7676     * Set up Smarty Template Engine 
     77     * 
     78     * @param string $template Template Name for "Frontloader" Rendering Engines (xtpl). 
    7779     */ 
    7880    public function initializeEngine($template = null) 
     
    212214         */ 
    213215        $tpl_array = array( $this->getThemeTemplatePaths(), # 1 + 2 
    214                             $this->getModuleTemplatePaths(), # 3 + 4         
    215                             ROOT_THEMES_CORE . 'view' . DS . 'smarty', # 5  
     216                            $this->getModuleTemplatePaths(), # 3 + 4 
     217                            ROOT_THEMES_CORE . 'view' . DS . 'smarty', # 5 
    216218                            ROOT_THEMES); # 6 
    217219 
     
    229231         * 3) clansuite module smarty plugins       => modules\module_name\viewhelper\smarty\ 
    230232         */ 
    231          
    232         $this->renderer->setPluginsDir(  
     233 
     234        $this->renderer->setPluginsDir( 
    233235            array( ROOT_LIBRARIES . 'smarty' . DS . 'plugins', 
    234                    ROOT_CORE . 'viewhelper' . DS . 'smarty' . DS,  
     236                   ROOT_CORE . 'viewhelper' . DS . 'smarty' . DS, 
    235237                   ROOT_MOD . Clansuite_TargetRoute::getModuleName() . DS . 'viewhelper' . DS. 'smarty' . DS 
    236238        )); 
     
    313315    public function assign($tpl_parameter, $value = null) 
    314316    { 
    315         if(is_array($tpl_parameter) === true) 
     317        if(is_array($tpl_parameter) === true or is_object($tpl_parameter) === true ) 
    316318        { 
    317319            $this->renderer->assign($tpl_parameter); 
     
    487489     * 
    488490     * @param string $templatename Template Filename 
     491     * @param array|object $data Data to assign to the view. 
    489492     * @return wrapper tpl layout 
    490493     */ 
    491     public function render($template) 
    492     { 
     494    public function render($template, $viewdata = null) 
     495    { 
     496        if(isset($viewdata)) 
     497        { 
     498            $this->assign($viewdata); 
     499        } 
     500 
    493501        # 1. assign common template values and Clansuite constants as Smarty Template Variables. 
    494502        $this->renderer->assignGlobal($this->getConstants()); 
  • trunk/core/renderer/xtemplate.renderer.php

    r5080 r5940  
    6464        if(class_exists('XTemplate', false) == false) 
    6565        { 
    66             # check if Smarty library exists 
     66            # check if library exists 
    6767            if(is_file(ROOT_LIBRARIES . 'xtemplate/xtemplate.class.php') === true) 
    6868            { 
     
    125125    } 
    126126 
    127     public function render($template) 
     127    public function render($template, $viewdata) 
    128128    { 
     129        $this->renderer->assign($viewdata); 
    129130        $this->renderer->parse($template); 
    130131        $this->renderer->out($template); 
Note: See TracChangeset for help on using the changeset viewer.