Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-28-2008, 08:01 AM
Junior Member
 
Join Date: May 2008
Posts: 6
Default How to disable init() in a action?

Hic hic,
I have a problem with function init() in my IndexAction class:
PHP Code:
class IndexController extends Zend_Cotroller_Action
{
      function 
init()
      {
            
$response $this->getResponse();
            
$response -> insert('footer'$this->view->render('footer.phtml'));
      }


      function 
indexAction()
      {
           
// my code
      
}


      function 
showCatAction()
      {
           
// my code
      
}

I want disable init() function when call showCatAction(), how do it? please help me!
__________________
Nắng sớm nhớ cha nợ cha một sự nghiệp
Chiều ta thương mẹ nợ mẹ một nàng dâu
----------------------------
Diễn đàn Nghệ An - Hà Tĩnh:
http://nghe-online.org/forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-11-2008, 11:27 AM
Junior Member
 
Join Date: Jul 2008
Posts: 6
Default

user varible $disactivateInit = false;

in init function
function init()
{
$disable = $_SESSION['disactivateInit'];
if ( $disable == true )return ;
$response = $this->getResponse();
$response -> insert('footer', $this->view->render('footer.phtml'));
}


in showCatAction :

function showCatAction()
{
// my code
$_SESSION['disactivateInit'] =true ;
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-11-2008, 11:47 AM
Junior Member
 
Join Date: Oct 2007
Location: Augusta, GA
Posts: 9
Default

A little foundational first....

init() is called by Zend_Controller_Action from the constructor method so you can add functionalities to the initialization of your controller class (done so you don't have to overload the parent __construct() magic method and have to do a parent::__construct() call). So, init() should be treated as if it was actually __construct().

For what you are trying to achieve, I would suggest that you do not assign the footer in the init() method. If you want to have the footer included by default, and be able to toggle it off if necessary (such as with the showCatAction() method), I would suggest you assign you footer placeholder a bit later on in the workflow, such as in postDispatch().

PHP Code:
class IndexController extends Zend_Cotroller_Action
{

      
/**
       * toggle footer rendering
       *
       * @var boolean
       */
       
protected $_renderFooter TRUE;

      function 
indexAction()
      {
           
// my code
      
}


      function 
showCatAction()
      {
           
$this->_noFooter();
      }

      public function 
postDispatch ()
      {
           if (
$this->_renderFooter === TRUE) {
               
//note, the footer is TRUE by default
               
$response -> insert('footer'$this->view->render('footer.phtml'));
           }
      }

      
/**
       * turn footer rendering off
       *
       * @return void
       */
       
protected function _noFooter () {
            
$this->_renderFooter FALSE;
            return;
       }


Hope this helps.

Steve
__________________
Steve Siebert
Zend Certified Engineer
General Dynamics IT
www.get-dev.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-16-2008, 09:06 AM
Junior Member
 
Join Date: May 2008
Posts: 6
Default

Thank you very much!
__________________
Nắng sớm nhớ cha nợ cha một sự nghiệp
Chiều ta thương mẹ nợ mẹ một nàng dâu
----------------------------
Diễn đàn Nghệ An - Hà Tĩnh:
http://nghe-online.org/forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 05:42 AM.