2017-04-15 64 views
0

我有一箇舊的項目我正在使用修身版2到3修身2渲染直接HTML

我試圖樹枝融入苗條2 ,同時也保持了舊我不能升級默認slim2渲染器。

目前我有這個。

class TwigView extends \Slim\View 
{ 
    public function rendertwig($template,$data = array()){ 
     global $twig; 

     $twigResults = $twig->render($template,array('test' => '1')); 

     $data = array_merge($this->data->all(), $data); 
     return $this->render($twigResults, $data); 
    } 

} 

$view = new TwigView(); 

$config['view'] = $view; //@JA - This command overides the default render method. 

//@JA - Intialize Slim 
$app = new \Slim\Slim($config); 

的想法是,我所說的這句話$app->view->rendertwig('file.twig')當我需要渲染的樹枝模板和使用$app->render('template.php')爲所有使用模板的默認slim2方法的其他模板。

但是,我得到一個錯誤,因爲在我的rendertwig函數$ this-> render()函數中需要第一個參數的模板名稱。 有沒有一種方法可以將樹枝結果直接渲染到超薄引擎而不需要模板文件?

我知道這是不好的形式有兩種模板引擎,但最終我將切換一切嫩枝但我需要這是一個臨時解決方案,直到我能修補所做的一切。

當我檢查slim的視圖對象時,它將它定義爲其渲染方法,它將解釋問題。

protected function render($template, $data = null) 
    { 
     $templatePathname = $this->getTemplatePathname($template); 
     if (!is_file($templatePathname)) { 
      throw new \RuntimeException("View cannot render `$template` because the template does not exist"); 
     } 

     $data = array_merge($this->data->all(), (array) $data); 
     extract($data); 
     ob_start(); 
     require $templatePathname; 

     return ob_get_clean(); 
    } 

回答

0

我不知道這是不好的形式,但我做了這個臨時解決方案。

class TwigView extends \Slim\View 
{ 
    public function rendertwig($template,$data = array()){ 
     global $twig; 

     $twigResults = $twig->render($template,array('test' => '1')); 
     echo $twigResults; 
    } 

} 

我看到所有渲染方法都只是需要模板,所以我認爲它的安全只是回聲從樹枝模板引擎的結果?這似乎從我的測試中起作用。