Development

Changeset 1853

You must first sign up to be able to contribute.

Changeset 1853

Show
Ignore:
Timestamp:
08/29/06 15:49:30 (2 years ago)
Author:
fabien
Message:

added the action to the parameters of the view (closes #814)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/config/sfViewConfigHandler.class.php

    r1828 r1853  
    6666      } 
    6767 
    68       $data[] = ($first ? '' : 'else ')."if (\$this->viewName == '$viewName')\n". 
     68      $data[] = ($first ? '' : 'else ')."if (\$this->actionName.\$this->viewName == '$viewName')\n". 
    6969                "{\n"; 
    7070 
  • trunk/lib/controller/sfController.class.php

    r1811 r1853  
    432432  { 
    433433    // user view exists? 
    434     $file = sfConfig::get('sf_app_module_dir').'/'.$moduleName.'/'.sfConfig::get('sf_app_module_view_dir_name').'/'.$viewName.'View.class.php'; 
     434    $file = sfConfig::get('sf_app_module_dir').'/'.$moduleName.'/'.sfConfig::get('sf_app_module_view_dir_name').'/'.$actionName.$viewName.'View.class.php'; 
    435435 
    436436    if (is_readable($file)) 
     
    438438      require_once($file); 
    439439 
    440       $class = $viewName.'View'; 
     440      $class = $actionName.$viewName.'View'; 
    441441 
    442442      // fix for same name classes 
     
    451451    { 
    452452      // view class (as configured in module.yml or defined in action) 
    453       $viewName = $this->getContext()->getRequest()->getAttribute($moduleName.'_'.$actionName.'_view_name', '', 'symfony/action/view') ? $this->getContext()->getRequest()->getAttribute($moduleName.'_'.$actionName.'_view_name', '', 'symfony/action/view') : sfConfig::get('mod_'.strtolower($moduleName).'_view_class'); 
     453      $viewName = $this->getContext()->getRequest()->getAttribute($moduleName.'_'.$actionName.'_view_name', sfConfig::get('mod_'.strtolower($moduleName).'_view_class'), 'symfony/action/view'); 
    454454      $file     = sfConfig::get('sf_symfony_lib_dir').'/view/'.$viewName.'View.class.php'; 
    455455      $class    = is_readable($file) ? $viewName.'View' : 'sfPHPView'; 
  • trunk/lib/filter/sfExecutionFilter.class.php

    r1639 r1853  
    143143    else if ($viewName != sfView::NONE) 
    144144    { 
    145       if (is_array($viewName)) 
    146       { 
    147         // we're going to use an entirely different action for this view 
    148         $moduleName = $viewName[0]; 
    149         $viewName   = $viewName[1]; 
    150       } 
    151       else 
    152       { 
    153         // use a view related to this action 
    154         $viewName = $actionName.$viewName; 
    155       } 
    156  
    157145      // get the view instance 
    158146      $viewInstance = $controller->getView($moduleName, $actionName, $viewName); 
    159147 
    160148      // initialize the view 
    161       if ($viewInstance->initialize($context, $moduleName, $viewName)) 
     149      if ($viewInstance->initialize($context, $moduleName, $actionName, $viewName)) 
    162150      { 
    163151        // view initialization completed successfully 
     
    166154        // render the view and if data is returned, stick it in the 
    167155        // action entry which was retrieved from the execution chain 
    168         $viewData =& $viewInstance->render(); 
     156        $viewData = $viewInstance->render(); 
    169157 
    170158        if ($controller->getRenderMode() == sfView::RENDER_VAR) 
  • trunk/lib/helper/PartialHelper.php

    r1850 r1853  
    300300 
    301301  // get the view instance 
    302   $viewName     = $templateName.$viewType; 
    303   $viewInstance = $controller->getView($moduleName, $actionName, $viewName); 
     302  $viewInstance = $controller->getView($moduleName, $actionName, $viewType); 
    304303 
    305304  // initialize the view 
    306   if (!$viewInstance->initialize($context, $moduleName, $viewName)) 
     305  if (!$viewInstance->initialize($context, $moduleName, $actionName, $viewType)) 
    307306  { 
    308307    // view failed to initialize 
    309308    $error = 'View initialization failed for module "%s", view "%sView"'; 
    310     $error = sprintf($error, $moduleName, $viewName); 
     309    $error = sprintf($error, $moduleName, $viewType); 
    311310 
    312311    throw new sfInitializationException($error); 
  • trunk/lib/view/sfPHPView.class.php

    r1833 r1853  
    150150    $context          = $this->getContext(); 
    151151    $actionStackEntry = $context->getController()->getActionStack()->getLastEntry(); 
    152     $action           = $actionStackEntry->getActionInstance(); 
    153152 
    154153    // store our current view 
     
    174173 
    175174    // require our configuration 
     175    $action = $actionStackEntry->getActionInstance(); 
    176176    $viewConfigFile = $this->moduleName.'/'.sfConfig::get('sf_app_module_config_dir_name').'/view.yml'; 
    177177    require(sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name').'/'.$viewConfigFile)); 
    178178 
    179     if (preg_match('/^(.+?)'.sfView::GLOBAL_PARTIAL.'$/i', $this->viewName, $match)
     179    if (sfView::GLOBAL_PARTIAL == $this->viewName
    180180    { 
    181181      // global partial 
    182       $templateFile = '_'.$match[1].$this->extension; 
     182      $templateFile = $this->actionName.$this->extension; 
    183183      $dirs = array(sfConfig::get('sf_app_template_dir')); 
    184184    } 
    185     else if (preg_match('/^(.+?)'.sfView::PARTIAL.'$/i', $this->viewName, $match)
     185    else if (sfView::PARTIAL == $this->viewName
    186186    { 
    187187      // partial 
    188       $templateFile = '_'.$match[1].$this->extension; 
    189     } 
    190     else if (preg_match('/^'.$action->getActionName().'(.+)$/i', $this->viewName, $match)) 
    191     { 
    192       $templateFile = $templateName.$match[1].$this->extension; 
     188      $templateFile = $this->actionName.$this->extension; 
    193189    } 
    194190    else 
    195191    { 
    196       $templateFile = $this->viewName.$this->extension; 
     192      $templateFile = $this->actionName.$this->viewName.$this->extension; 
    197193    } 
    198194 
     
    255251   *                the controller render mode is sfView::RENDER_VAR, otherwise null. 
    256252   */ 
    257   public function &render($templateVars = null) 
    258   { 
    259     $retval = null; 
    260  
     253  public function render($templateVars = null) 
     254  { 
    261255    $context = $this->getContext(); 
    262256 
     
    264258    $mode = $context->getController()->getRenderMode(); 
    265259 
    266     if ($mode != sfView::RENDER_NONE) 
    267     { 
    268       $retval = null; 
    269       if (sfConfig::get('sf_cache')) 
    270       { 
    271         $response = $context->getResponse(); 
    272         $key   = $response->getParameterHolder()->remove('current_key', 'symfony/cache/current'); 
    273         $cache = $response->getParameter($key, null, 'symfony/cache'); 
    274         if ($cache !== null) 
     260    if ($mode == sfView::RENDER_NONE) 
     261    { 
     262      return null; 
     263    } 
     264 
     265    $retval = null; 
     266    if (sfConfig::get('sf_cache')) 
     267    { 
     268      $response = $context->getResponse(); 
     269      $key   = $response->getParameterHolder()->remove('current_key', 'symfony/cache/current'); 
     270      $cache = $response->getParameter($key, null, 'symfony/cache'); 
     271      if ($cache !== null) 
     272      { 
     273        $cache  = unserialize($cache); 
     274        $retval = $cache['content']; 
     275        $vars   = $cache['vars']; 
     276        $response->mergeProperties($cache['response']); 
     277      } 
     278    } 
     279 
     280    // template variables 
     281    if ($templateVars === null) 
     282    { 
     283      $actionStackEntry = $context->getActionStack()->getLastEntry(); 
     284      $actionInstance   = $actionStackEntry->getActionInstance(); 
     285      $templateVars     = $actionInstance->getVarHolder()->getAll(); 
     286    } 
     287 
     288    // assigns some variables to the template 
     289    $this->attribute_holder->add($this->getGlobalVars()); 
     290    $this->attribute_holder->add($retval !== null ? $vars : $templateVars); 
     291 
     292    // render template if no cache 
     293    if ($retval === null) 
     294    { 
     295      // execute pre-render check 
     296      $this->preRenderCheck(); 
     297 
     298      // render template file 
     299      $template = $this->getDirectory().'/'.$this->getTemplate(); 
     300      $retval = $this->renderFile($template); 
     301 
     302      if (sfConfig::get('sf_cache') && $key !== null) 
     303      { 
     304        $cache = array( 
     305          'content'   => $retval, 
     306          'vars'      => $templateVars, 
     307          'view_name' => $this->viewName, 
     308          'response'  => $context->getResponse(), 
     309        ); 
     310        $response->setParameter($key, serialize($cache), 'symfony/cache'); 
     311 
     312        if (sfConfig::get('sf_web_debug')) 
    275313        { 
    276           $cache  = unserialize($cache); 
    277           $retval = $cache['content']; 
    278           $vars   = $cache['vars']; 
    279           $response->mergeProperties($cache['response']); 
     314          $retval = sfWebDebug::getInstance()->decorateContentWithDebug($key, '', $retval, true); 
    280315        } 
    281316      } 
    282  
    283       // template variables 
    284       if ($templateVars === null) 
    285       { 
    286         $actionStackEntry = $context->getActionStack()->getLastEntry(); 
    287         $actionInstance   = $actionStackEntry->getActionInstance(); 
    288         $templateVars     = $actionInstance->getVarHolder()->getAll(); 
    289       } 
    290  
    291       // assigns some variables to the template 
    292       $this->attribute_holder->add($this->getGlobalVars()); 
    293       $this->attribute_holder->add($retval !== null ? $vars : $templateVars); 
    294  
    295       // render template if no cache 
    296       if ($retval === null) 
    297       { 
    298         // execute pre-render check 
    299         $this->preRenderCheck(); 
    300  
    301         // render template file 
    302         $template = $this->getDirectory().'/'.$this->getTemplate(); 
    303         $retval = $this->renderFile($template); 
    304  
    305         if (sfConfig::get('sf_cache') && $key !== null) 
    306         { 
    307           $cache = array( 
    308             'content'   => $retval, 
    309             'vars'      => $templateVars, 
    310             'view_name' => $this->viewName, 
    311             'response'  => $context->getResponse(), 
    312           ); 
    313           $response->setParameter($key, serialize($cache), 'symfony/cache'); 
    314  
    315           if (sfConfig::get('sf_web_debug')) 
    316           { 
    317             $retval = sfWebDebug::getInstance()->decorateContentWithDebug($key, '', $retval, true); 
    318           } 
    319         } 
    320       } 
    321  
    322       // now render decorator template, if one exists 
    323       if ($this->isDecorator()) 
    324       { 
    325         $retval = $this->decorate($retval); 
    326       } 
    327  
    328       // render to client 
    329       if ($mode == sfView::RENDER_CLIENT) 
    330       { 
    331         $context->getResponse()->setContent($retval); 
    332       } 
     317    } 
     318 
     319    // now render decorator template, if one exists 
     320    if ($this->isDecorator()) 
     321    { 
     322      $retval = $this->decorate($retval); 
     323    } 
     324 
     325    // render to client 
     326    if ($mode == sfView::RENDER_CLIENT) 
     327    { 
     328      $context->getResponse()->setContent($retval); 
    333329    } 
    334330 
  • trunk/lib/view/sfView.class.php

    r1643 r1853  
    9999    $parameter_holder   = null, 
    100100    $moduleName         = '', 
     101    $actionName         = '', 
    101102    $viewName           = '', 
    102103    $extension          = '.php'; 
     
    311312   * @param Context The current application context. 
    312313   * @param string The module name for this view. 
     314   * @param string The action name for this view. 
    313315   * @param string The view name. 
    314316   * 
    315317   * @return bool true, if initialization completes successfully, otherwise false. 
    316318   */ 
    317   public function initialize ($context, $moduleName, $viewName) 
     319  public function initialize ($context, $moduleName, $actionName, $viewName) 
    318320  { 
    319321    $this->moduleName = $moduleName; 
     322    $this->actionName = $actionName; 
    320323    $this->viewName   = $viewName; 
    321324 
     
    447450   *                the controller render mode is sfView::RENDER_VAR, otherwise null. 
    448451   */ 
    449   abstract function & render ($templateVars = null); 
     452  abstract function render ($templateVars = null); 
    450453 
    451454  /**