简体   繁体   中英

Zend Framework :: ignoring predispatch for particular action

I am a newbie to Zend framework, I want to know how can we restrict the call to predispatch() function in my controller for any particular action.

-DevD

In your controller try

public function preDispatch()
{
    if($this->getRequest()->getActionName() === 'actionName') {
        return; // ignoring preDispatch
    }
    // run preDispatch code when not actionName
}

The preDispatch method is called before any controller Actions are called in the MVC Request Lifecyle. Thus, you cannot disable preDispatch from an individual action.

You can create a property inside your controller or a variable in the preDispatch method where you put in the action names (without the Action suffix) you want preDispatch to return from without doing anything. In the example code above, you wouldn't test against one action name but against the list of action names, probably with in_array.

See http://devzone.zend.com/article/11978-Zend-Framework-MVC-Request-Lifecycle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM