Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4997228
  • 博文数量: 921
  • 博客积分: 16037
  • 博客等级: 上将
  • 技术积分: 8469
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-05 02:08
文章分类

全部博文(921)

文章存档

2020年(1)

2019年(3)

2018年(3)

2017年(6)

2016年(47)

2015年(72)

2014年(25)

2013年(72)

2012年(125)

2011年(182)

2010年(42)

2009年(14)

2008年(85)

2007年(89)

2006年(155)

分类:

2010-02-25 12:24:22

摘要: Zend Framework 内置了 MVC 开发架构,功能非常强大,其中 Zend_Controller 在使用的时候会根据 module/controller/action 自动解析对应的 view ,如果找不到就会抛错;但是有时候我们并不想使用 view 层,这时候我们就需要禁用 view 或者 layout 了,本文就是对禁用 view 或者 layout 所做的总结。
 
小标题:

在 Action 级别禁用 view:



PHP:

  1.  
  2. class FooController extends Zend_Controller_Action
  3. {
  4. public function barAction()
  5. {
  6. $this->_helper->viewRenderer->setNoRender();
  7. }
  8. }
  9. ?>
  10.  



在执行当前 action 的时候会不会展示 view .

在 Controller 级别禁用 view:



PHP:

  1.  
  2. class FooController extends Zend_Controller_Action
  3. {
  4. public function init()
  5. {
  6. $this->_helper->viewRenderer->setNoRender();
  7. }
  8. }
  9. ?>
  10.  



在执行当前 controller 下的所有 action 的时候都不会展示 view .

全局级别禁用 view:



PHP:

  1.  
  2. Zend_Controller_Front::getInstance()->setParam('noViewRenderer', true);
  3. ?>
  4.  



在整个程序的执行过程中都不会展示 view .

 

 


禁用 layout

  1.  
  2. class FooController extends Zend_Controller_Action
  3. {
  4. public function barAction()
  5. {
  6. $this->_helper->layout->disableLayout();
  7. }
  8. }
  9. ?>
  10.  


在此 action 执行的时候将不会使用 Zend_Layout 。


改变 layout

  1.  
  2. class FooController extends Zend_Controller_Action
  3. {
  4. public function barAction()
  5. {
  6. $this->_helper->layout->setLayout('other');
  7. }
  8. }
  9. ?>
  10.  


在此 action 执行的时候将使用名为 other 的 layout 。
 
阅读(1829) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~