phalcon框架模板设置必须以phtml?

WBOY
Release: 2016-06-06 20:31:50
Original
1538 people have browsed it

phalcon框架模板设置必须以phtml?
我设置index.html之后,刷新页面出现index.html.php
我想知道何解啊

而且我想知道在依赖注入那块

phalcon框架模板设置必须以phtml?

为什么不能在models里用$this->db,是这款框架设计的原因么?

回复内容:

phalcon框架模板设置必须以phtml?
我设置index.html之后,刷新页面出现index.html.php
我想知道何解啊

而且我想知道在依赖注入那块

phalcon框架模板设置必须以phtml?

为什么不能在models里用$this->db,是这款框架设计的原因么?

1、模板后缀可以设置
参见:Phalcon激活volt
2、依赖注入,实现全局懒惰加载 lazy load

  1. 注册模板引擎:
<code>php</code><code>/**
 2. view 
 */
$di->setShared('view', function() use ($config) {
    $view = new \Phalcon\Mvc\View();
    $view->setViewsDir($config->application->viewsDir);
    $view->registerEngines([
        '.phtml' => '\Phalcon\Mvc\View\Engine\Php',
        '.volt' => function($view, $di) use ($config) {
            $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);

            $volt->setOptions(['compiledPath'       => $config->application->cacheDir . 'view/',
                                'compiledExtension' => '.compiled',
                                'compileAlways'     => true
            ]);

            $compiler = $volt->getCompiler();
            $compiler->addFilter('floor', 'floor');
            $compiler->addFunction('range', 'range');

            return $volt;
        },
            ]);

    return $view;
});
</code>
Copy after login
  1. 在Model里面引用注册的服务:
<code>php</code><code>    $this->getDI()->get('db')->.......
</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!