【问题标题】:Phalcon volt template enginePhalcon volt模板引擎
【发布时间】:2012-10-31 08:13:27
【问题描述】:
$di = new \Phalcon\DI\FactoryDefault();

/**
 * The URL component is used to generate all kind of urls in the application
 */
$di->set('url', function() use ($config) {
    $url = new \Phalcon\Mvc\Url();
    $url->setBaseUri($config->application->baseUri);
    return $url;
});

$di->set('voltService', function()  {
    $volt = new Phalcon\Mvc\View\Engine\Volt($view, $di);
    $volt->setOptions(array(
        "compiledPath" => "../app/compiled/",
        "compiledExtension" => ".php"
    ));
    return $volt;
});

/**
 * Setting up the view component
 */
$di->set('view', function() use ($config) {
    $view = new \Phalcon\Mvc\View();
    $view->setViewsDir($config->application->viewsDir);
    $view->registerEngines(array(".phtml" => 'voltService'));
    return $view;
});

我用这篇文章:http://docs.phalconphp.com/en/0.6.0/reference/volt.html,但是提示错误信息

注意:未定义变量:查看 /var/www/html/phalconblog/public/index.php 第 40 行

注意:未定义的变量:di in /var/www/html/phalconblog/public/index.php 第 40 行

致命错误:调用未定义的方法 Phalcon\Mvc\View\Engine\Volt::setOptions() 在 /var/www/html/phalconblog/public/index.php 第 42 行

【问题讨论】:

    标签: phalcon volt


    【解决方案1】:

    我也试过了,但也遇到了类似的问题 - 不知道为什么。

    编辑

    正确的做法是:

    // Register Volt as a service
    $di->set(
        'volt', 
        function($view, $di) 
        {
            $volt = new Phalcon\Mvc\View\Engine\Volt($view, $di);
    
            $volt->setOptions(
                array(
                    'compiledPath'      => $config->volt->path,
                    'compiledExtension' => $config->volt->extension,
                    'compiledSeparator' => $config->volt->separator,
                    'stat'              => (bool) $config->volt->stat,
                )
            );
    
            return $volt;
        }
    );
    
    // Register Volt as template engine
    $di->set(
        'view', 
        function() 
        {
            $view = new \Phalcon\Mvc\View();
            $view->setViewsDir($config->application->viewsDir);
    
            $view->registerEngines(array(".volt" => 'volt'));
    
            return $view;
        }
    );
    

    以下是一种解决方法,但不建议使用:

    /**
     * Setting up the view component
     */
    $di->set(
        'view', 
        function() use ($config, $di) 
        {
            $view = new \Phalcon\Mvc\View();
            $view->setViewsDir($config->application->viewsDir);
    
            $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
            $volt->setOptions(
                array(
                    'compiledPath'      => $config->volt->path,
                    'compiledExtension' => $config->volt->extension,
                    'compiledSeparator' => $config->volt->separator,
                    'stat'              => (bool) $config->volt->stat,
                )
            );
    
            /**
             * Register Volt
             */
            $view->registerEngines(array('.phtml' => $volt));
    
            return $view;
        }
    );
    

    【讨论】:

      猜你喜欢
      • 2016-01-29
      • 2014-05-14
      • 2014-11-11
      • 1970-01-01
      • 1970-01-01
      • 2016-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多