Search code examples
phpphalcon

DI,Service Name Conventions.why not has viewCache?


http://docs.phalconphp.com/en/0.6.0/reference/di.html

in public/index.php, codeing :

$di->set('viewCache', function(){

    //Cache data for one day by default
    $frontCache = new Phalcon\Cache\Frontend\Output(array(
            "lifetime" => 86400
    ));

    //Memcached connection settings
    $cache = new Phalcon\Cache\Backend\File($frontCache, array(
            "cacheDir" => "../apps/caches/"
    ));

    return $cache;
});

that,in controller,i can use this->view->cache(), why not viewCache not in service name conventions?


Solution

  • The service viewCache can be accessed like this:

    // In controller
    $this->view->cache();
    

    or

    // In controller 
    $this->di->get('viewCache');
    

    or

    // In a module or other file
    $di = \Phalcon\DI::getDefault();
    $di->get('viewCache');