How to get the Request Object from a Model using Zend Framework.
Is there anyway that I can get the request params directly from the model in zend framework? I need it for a constructor, so it doesn't actually need contact with the database.
In a controller it's easy to get the request... Something like $this->getRequest()->getParam('id');
but in a model that won't work obviously. I开发者_JAVA百科 just need to get an instance of the controller, and then I can call the getRequest()->getParam('id')
methods.
Yes there is, but you are doing it wrong. For the purposes of answering the question this is how you do it....(but don't). You should pass the param to your model, rather than getting the param.
How to get the Request from Anywhere
> $fc = Zend_Controller_Front::getInstance();
> $fc->getRequest()->getParam('id');
But how you should be doing it (Assuming within controller context)
$model = new Model();
$model->getItemById( $this->getRequest()->getParam('id') );
精彩评论