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

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

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

图片描述

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

阅读 6.5k
2 个回答
  1. 注册模板引擎:
php/**
 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;
});
  1. 在Model里面引用注册的服务:
php    $this->getDI()->get('db')->.......
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题