Something I've toyed around with is using the Zend_Form object as the
"data police" or some other object for handling validation. IMO, the
controller is responsible for dispatching events or messages to other
objects. It should simply know if something is valid or invalid and
where to send the data off to in each instance.
I think having a db connection in your controller is only really
dangerous if you have multiple resources (like db's, web services,
etc...) that are being instantiated over and over again in different
controllers. At that point it probably makes sense to create some sort
of facade or singleton for handling the brokering between various
services.
On 28-May-09, at 11:04 AM, Jason Webster wrote:
This would be really easy with a action helper (untested, but you
get the idea):
class My_Controller_Action_Helper_Bootstrap extends
Zend_Controller_Action_Helper_Abstract
{
public function __get($name) {
return $this->getActionController()->getInvokeArg('bootstrap')-
>getResource($name);
}
}
Then in your controller:
$acl = $this->_helper->bootstrap->acl;
Of course, I'd probably name it the Resource action helper, or
somesuch.
On 26/05/2009 2:52 PM, swilhelm wrote:
I predict we will see this question every so often until the
bootstrap
becomes more directly accessible, like the view.
So in a controller's action method, something like:
$this->bootstrap->db;
would be nice.
- Steve W.
Matthew Weier O'Phinney-3 wrote:
-- Vladas Diržys<[email protected]> wrote
(on Tuesday, 26 May 2009, 09:40 PM +0300):
what is the right way to get a db (or any other) resource in the
controller?
Now I'm using following line:
$this->getFrontController()->getParam('bootstrap')-
>getResource('db');
Is there a better way?
Within your controller, yes, there's an easier way:
$this->getInvokeArg('bootstrap')->getResource('db');
--
Matthew Weier O'Phinney
Project Lead | [email protected]
Zend Framework | http://framework.zend.com/