user2599145
user2599145

Reputation: 11

Yii: Zend's preDispatch and init analogon

I have to translate an applications from Zend to Yii Framework. Since i'm new to Zend, i wonder how to implement the Controllers preDispatch() and init() functions in Yii. Thanks for advice.

Upvotes: 1

Views: 241

Answers (1)

user133408
user133408

Reputation:

For init there is same initfunction in Yii controllers.

public function init()
{
    // Do some initialization
}

For predispatch you can use beforeAction, this will be called just before action - return true if you want action to be executed, or false to cancel execution.

protected function beforeAction($action) {          
    // Do some logic just before action
    return true;
}

When ovveriding custom controller parent methods should be called.

There is also very usefull filter for actions

Upvotes: 2

Related Questions