2012-10-31 4 views
1
이 글을 사용
$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하지만, 팁 오류 메시지가Phalcon 볼트 템플릿 엔진

Notice: Undefined variable: view in /var/www/html/phalconblog/public/index.php on line 40

Notice: Undefined variable: di in /var/www/html/phalconblog/public/index.php on line 40

Fatal error: Call to undefined method Phalcon\Mvc\View\Engine\Volt::setOptions() in /var/www/html/phalconblog/public/index.php on line 42

답변

3

나는 너무 시도하고 비슷한 문제가 있었다 - 왜 확실하지합니다.

편집

올바른 방법은 다음과 같습니다

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