dean jase
dean jase

Reputation: 1161

zend model using helpers

Call to undefined method Application_Model_Users::_helper()

how can i get the redirect helper to work in models? in works in the controllers that extends the zend controller action but not in models

thanks

Upvotes: 1

Views: 931

Answers (1)

Gordon
Gordon

Reputation: 316959

You can either fetch it from the within the model:

$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');

or fetch the helper in the controller and inject it to the model, which would be somewhat cleaner:

$redirector = $this->_helper->getHelper('redirector');
$userModel = new Application_Model_Users($redirector);

But …

… like it was already pointed out in the comments - nothing in the Model should be responsible for redirecting a request, so I strongly suggest you dont do this in the Model at all. Keep this in the controller.

Upvotes: 5

Related Questions