One of the problems I've found with pulling the bootstrap from the front
controller (besides the singleton issue) is that the front controller in my
test environment didn't have the bootstrap param. I had to manually set it
within my appBootStrap() for my tests to work:

public function appBootStrap()
{
 $this->_application = new Zend_Application(
 APPLICATION_ENV,
 APPLICATION_PATH . '/configs/application.ini'
 );
 $this->_application->bootstrap();
 *$this->frontController->setParam('bootstrap',
$this->_application->getBootstrap());*
}

A better approach would be to inject your model with its dependencies:

// in controller
$model = new MyModel();
$cacheManager =
$this->getInvokeArg('bootstrap')->getResource('cachemanager');
$model->setCacheManager($cacheManager);
// do stuff with model

But again, in the testing environment, you'll need to manually inject the
bootstrap into the front controller.

--
Hector


On Fri, Feb 12, 2010 at 5:17 AM, Pádraic Brady <[email protected]>wrote:

> Simplest method from anywhere:
>
>
> Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('cachemanager');
>
> It's downfall is it adds a dependency on a singleton, but without knowing
> how your model works it's difficult to suggest a better alternative without
> the singleton.
>
> Pádraic Brady
>
> http://blog.astrumfutura.com
> http://www.survivethedeepend.com
> OpenID Europe Foundation Irish Representative<http://www.openideurope.eu/>
>
>
> ------------------------------
> *From:* Marko78 <[email protected]>
> *To:* [email protected]
> *Sent:* Fri, February 12, 2010 12:38:11 PM
> *Subject:* [fw-general] Hot to get cacheManager resource from anywhere?
>
>
> Hi,
>
> I have set up cacheManager in my application.ini and I want to get it from
> my Model.
>
> How can I get it?
>
> br, Marko
> --
> View this message in context:
> http://n4.nabble.com/Hot-to-get-cacheManager-resource-from-anywhere-tp1478479p1478479.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>

Reply via email to