1

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(),为什么不在服务名称约定中使用 viewCache?

4

1 回答 1

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');
于 2012-11-06T13:42:08.813 回答