boosis wrote
> 
> Hi cmple,
> 
> That didn't work initially, threw this message
> PHP Fatal error:  Uncaught exception 'ReflectionException' with message
> 'Class Zend\\Cache\\Storage\\Adapter does not exist'
> changed the adapter to abstractadapter and it worked. But could you tell
> me
> how to configure the Filesystem cache adapter, ie, I want to change the
> cacheDir.
> 
> 
> Thanks
> Bill
> 
> 
> On 12 May 2012 18:45, cmple <roman.vidyayev@> wrote:
> 
>> Hey Bill,
>>
>> This should work:
>>
>> http://zend-framework-community.634137.n4.nabble.com/ZF2-Factory-method-and-Zend-Di-td4257197.html#a4557174
>>
>>
>> boosis wrote
>> >
>> > Hi,
>> >
>> > I am trying to inject Zend Filesystem cache to my service class but
>> > couldn't manage to do it. My DI configuration looks like this
>> >
>> > return array(
>> >     'di' => array(
>> >         'instance' => array(
>> >             'alias' => array(
>> >                 'file_cache' =>
>> 'Zend\Cache\Storage\Adapter\Filesystem',
>> >                 'file_cache_options' =>
>> > 'Zend\Cache\Storage\Adapter\FilesystemOptions',
>> >             ),
>> >             'file_cache_options' => array(
>> >                 'parameters' => array(
>> >                     'cacheDir' => '/opt',
>> >                     'dirUmask' => '0777'
>> >                 ),
>> >             ),
>> >             'file_cache' => array(
>> >                 'parameters' => array(
>> >                     'options' => 'file_cache_options'
>> >                 ),
>> >             ),
>> >             'Application\Domain\Service\Deal' => array(
>> >                 'parameters' => array(
>> >                     'mapper' => 'Application\Domain\Mapper\Deal',
>> >                     'cache'  => 'file_cache'
>> >                 ),
>> >             ),
>> >
>> > But when I dump the cache object in the Mapper Deal object I get the
>> cache
>> > object with default settings. i.e. I try to set the cacheDir to /opt
>> but
>> > dump still shows /tmp. So I guess FilesystemOptions is not injected
>> > correctly.
>> >
>> > Could someone shed some light on this?
>> >
>> > Thanks
>> > Bill
>> >
>>
>>
>> --
>> View this message in context:
>> http://zend-framework-community.634137.n4.nabble.com/Setting-up-Zend-Filesystem-Cache-with-DI-tp4629194p4629212.html
>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>
>> --
>> List: [email protected]
>> Info: http://framework.zend.com/archives
>> Unsubscribe: [email protected]
>>
>>
>>
> 
try this:

//module.config.php
<?php
return array(
    'di' => array(
        'definition' => array(
            'class' => array(
                'Zend\Cache\Storage\Adapter\Filesystem' => array(
                    'instantiator' => array(
                        'Zend\Cache\StorageFactory',
                        'factory'
                    ),
                ),
                'Zend\Cache\StorageFactory' => array(
                    'methods' => array(
                        'factory' => array('cfg' => array(
                                'required' => true,
                                'type' => false,
                        ))
                    ),
                ),
            ),
        ),
        'instance' => array(
                'alias' => array(
                        'cache' => 'Zend\Cache\Storage\Adapter\Filesystem',     
                
                ),
                'cache' => array(
                        'parameters' => array('cfg' => array(
                            'adapter' => array(
                                'name' => 'filesystem',
                                'options' => array(
                                        'dirLevel' => 2,
                                        *'cacheDir' => __DIR__ . 
'/../../../data/cache',*
                                ),
                            ),
                            'plugins' => array(
                                'serializer'
                        ),
                        ),
                ),
            ),
            
        ),
    ),
);


//Module/Module.php
<?php

namespace Application;

use Zend\Module\Manager,
    Zend\EventManager\StaticEventManager,
    Zend\Module\Consumer\AutoloaderProvider,
    Zend\Navigation\Page\Mvc as PageMvc;

class Module implements AutoloaderProvider {

        //....
        
    public function initializeView($e)
    {
        $app          = $e->getParam('application');
        $basePath     = $app->getRequest()->getBasePath();
        $locator      = $app->getLocator();
        $renderer     = $locator->get('Zend\View\Renderer\PhpRenderer');
        $renderer->plugin('url')->setRouter($app->getRouter());
        $renderer->doctype()->setDoctype('HTML5');
        $renderer->plugin('basePath')->setBasePath($basePath);
        
        $this->setCache($locator->get('cache'));

    }
    
    public static function getCache() {
        return static::$cache;
    }
    
    public function setCache($cache) {
        static::$cache = $cache;
    }
    
  //....
}




<?php
namespace Application\Model;

use Application\Module;

class MyModel {

        public function cacheTest(){
                
                $cache = Module::getCache();
                //... do some cache magic
                
        }
        
}

--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/Setting-up-Zend-Filesystem-Cache-with-DI-tp4629194p4629759.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to