DI,服务名称约定。为什么没有viewCache?

时间:2012-11-06 03:50:32

标签: php phalcon

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

在public / index.php中,编码:

$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;
});

在控制器中,我可以使用this-> view-> cache(),为什么不在服务名称约定中查看Cache呢?

1 个答案:

答案 0 :(得分:0)

可以像这样访问服务viewCache

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

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

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