Changeset 1853
- Timestamp:
- 08/29/06 15:49:30 (2 years ago)
- Files:
-
- trunk/lib/config/sfViewConfigHandler.class.php (modified) (1 diff)
- trunk/lib/controller/sfController.class.php (modified) (3 diffs)
- trunk/lib/filter/sfExecutionFilter.class.php (modified) (2 diffs)
- trunk/lib/helper/PartialHelper.php (modified) (1 diff)
- trunk/lib/view/sfPHPView.class.php (modified) (4 diffs)
- trunk/lib/view/sfView.class.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/config/sfViewConfigHandler.class.php
r1828 r1853 66 66 } 67 67 68 $data[] = ($first ? '' : 'else ')."if (\$this-> viewName == '$viewName')\n".68 $data[] = ($first ? '' : 'else ')."if (\$this->actionName.\$this->viewName == '$viewName')\n". 69 69 "{\n"; 70 70 trunk/lib/controller/sfController.class.php
r1811 r1853 432 432 { 433 433 // 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'; 435 435 436 436 if (is_readable($file)) … … 438 438 require_once($file); 439 439 440 $class = $ viewName.'View';440 $class = $actionName.$viewName.'View'; 441 441 442 442 // fix for same name classes … … 451 451 { 452 452 // 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'); 454 454 $file = sfConfig::get('sf_symfony_lib_dir').'/view/'.$viewName.'View.class.php'; 455 455 $class = is_readable($file) ? $viewName.'View' : 'sfPHPView'; trunk/lib/filter/sfExecutionFilter.class.php
r1639 r1853 143 143 else if ($viewName != sfView::NONE) 144 144 { 145 if (is_array($viewName))146 {147 // we're going to use an entirely different action for this view148 $moduleName = $viewName[0];149 $viewName = $viewName[1];150 }151 else152 {153 // use a view related to this action154 $viewName = $actionName.$viewName;155 }156 157 145 // get the view instance 158 146 $viewInstance = $controller->getView($moduleName, $actionName, $viewName); 159 147 160 148 // initialize the view 161 if ($viewInstance->initialize($context, $moduleName, $ viewName))149 if ($viewInstance->initialize($context, $moduleName, $actionName, $viewName)) 162 150 { 163 151 // view initialization completed successfully … … 166 154 // render the view and if data is returned, stick it in the 167 155 // action entry which was retrieved from the execution chain 168 $viewData = &$viewInstance->render();156 $viewData = $viewInstance->render(); 169 157 170 158 if ($controller->getRenderMode() == sfView::RENDER_VAR) trunk/lib/helper/PartialHelper.php
r1850 r1853 300 300 301 301 // get the view instance 302 $viewName = $templateName.$viewType; 303 $viewInstance = $controller->getView($moduleName, $actionName, $viewName); 302 $viewInstance = $controller->getView($moduleName, $actionName, $viewType); 304 303 305 304 // initialize the view 306 if (!$viewInstance->initialize($context, $moduleName, $ viewName))305 if (!$viewInstance->initialize($context, $moduleName, $actionName, $viewType)) 307 306 { 308 307 // view failed to initialize 309 308 $error = 'View initialization failed for module "%s", view "%sView"'; 310 $error = sprintf($error, $moduleName, $view Name);309 $error = sprintf($error, $moduleName, $viewType); 311 310 312 311 throw new sfInitializationException($error); trunk/lib/view/sfPHPView.class.php
r1833 r1853 150 150 $context = $this->getContext(); 151 151 $actionStackEntry = $context->getController()->getActionStack()->getLastEntry(); 152 $action = $actionStackEntry->getActionInstance();153 152 154 153 // store our current view … … 174 173 175 174 // require our configuration 175 $action = $actionStackEntry->getActionInstance(); 176 176 $viewConfigFile = $this->moduleName.'/'.sfConfig::get('sf_app_module_config_dir_name').'/view.yml'; 177 177 require(sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name').'/'.$viewConfigFile)); 178 178 179 if ( preg_match('/^(.+?)'.sfView::GLOBAL_PARTIAL.'$/i', $this->viewName, $match))179 if (sfView::GLOBAL_PARTIAL == $this->viewName) 180 180 { 181 181 // global partial 182 $templateFile = '_'.$match[1].$this->extension;182 $templateFile = $this->actionName.$this->extension; 183 183 $dirs = array(sfConfig::get('sf_app_template_dir')); 184 184 } 185 else if ( preg_match('/^(.+?)'.sfView::PARTIAL.'$/i', $this->viewName, $match))185 else if (sfView::PARTIAL == $this->viewName) 186 186 { 187 187 // 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; 193 189 } 194 190 else 195 191 { 196 $templateFile = $this-> viewName.$this->extension;192 $templateFile = $this->actionName.$this->viewName.$this->extension; 197 193 } 198 194 … … 255 251 * the controller render mode is sfView::RENDER_VAR, otherwise null. 256 252 */ 257 public function &render($templateVars = null) 258 { 259 $retval = null; 260 253 public function render($templateVars = null) 254 { 261 255 $context = $this->getContext(); 262 256 … … 264 258 $mode = $context->getController()->getRenderMode(); 265 259 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')) 275 313 { 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); 280 315 } 281 316 } 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); 333 329 } 334 330 trunk/lib/view/sfView.class.php
r1643 r1853 99 99 $parameter_holder = null, 100 100 $moduleName = '', 101 $actionName = '', 101 102 $viewName = '', 102 103 $extension = '.php'; … … 311 312 * @param Context The current application context. 312 313 * @param string The module name for this view. 314 * @param string The action name for this view. 313 315 * @param string The view name. 314 316 * 315 317 * @return bool true, if initialization completes successfully, otherwise false. 316 318 */ 317 public function initialize ($context, $moduleName, $ viewName)319 public function initialize ($context, $moduleName, $actionName, $viewName) 318 320 { 319 321 $this->moduleName = $moduleName; 322 $this->actionName = $actionName; 320 323 $this->viewName = $viewName; 321 324 … … 447 450 * the controller render mode is sfView::RENDER_VAR, otherwise null. 448 451 */ 449 abstract function &render ($templateVars = null);452 abstract function render ($templateVars = null); 450 453 451 454 /**