Thx Hector.
Nice answer and useful code example.
Is there a reason to use registry over bootstrap init and get resource?
Is it better to do
if (Zend_Registry::has('cache')) {
$this->setCache(Zend_Registry::get('cache'));
}
or
if ($cache = $this->setCache(Zend_Registry::get('cache'))) {
//
}
Regards,
Saša Stamenković
On Mon, Oct 5, 2009 at 8:06 PM, Hector Virgen <[email protected]> wrote:
> If it's system-wide, I usually place it in the registry for easy access.
> But then I also use a lazy-loading technique in the model layer that pulls
> the cache from the registry if it wasn't set:
> public function setCache(Zend_Cache_Core $cache)
> {
> $this->_cache = $cache;
> return $this;
> }
>
> public function getCache()
> {
> if (null === $this->_cache) {
> if (Zend_Registry::has('cache')) {
> $this->setCache(Zend_Registry::get('cache'));
> }
> }
> return $this->_cache;
> }
>
> --
> Hector
>
>
>
> On Mon, Oct 5, 2009 at 1:03 AM, umpirsky <[email protected]> wrote:
>
>>
>> Hi.
>>
>> I need several Zend_Cache objects for my app (file, memcached...), and I
>> don't want to instantiate and initialize it all over my app. So, there are
>> 2
>> options:
>>
>> - Init Zend_Cache in bootstrap and then get it all over app (in models for
>> ex) with:
>> $this->getFrontController()->getParam('bootstrap')->getResource('cache');
>> -
>> if I can do this in models at all? How do I access bootstrap resources
>> from
>> outside controllers?
>> - Init Zend_Cache in bootstrap but store it in Zend_Registry then get it
>> with Zend_Registry::get('cache');
>>
>> What is better/faster approach and why?
>> --
>> View this message in context:
>> http://www.nabble.com/Application-Resources-Access-tp25746631p25746631.html
>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>
>>
>