2012-01-27 11 views
0

私はKohanaテンプレートクラスを拡張するKohanaコントローラを持っています。私はいくつかのメソッドを持って、このコントローラでも

public $template = 'homepage_template'; 

、およびいくつかの関連するビュー:Kohanaのテンプレートクラスは、私が使用するテンプレートのビューを宣言している。このコントローラで

const CONTENT_KEY = 'content'; 

を持っています。

I homepage_templateビューでecho $content、何もショー(このコントローラからの操作に属しビューからコンテンツなし)、これらすべてを持ちます。 (私はアクションでauto_renderをtrueにしています)。何が原因なの?

+1

Kohanaのバージョンはこれですか?アプリケーション内でより特定のファイルパスを与えることはできますか?サイレントエラーのWebサーバーエラーログを確認しましたか? – Lethargy

+0

あなたは「Kohana template」クラスを使用しているかどうかを具体的に知ることができますか? Kohana Template Controllerを意味しますか?もしそうなら、実際にあなたの行動にコンテンツビューのvarを設定していますか?例:$ this-> template-> content = View :: factory( 'whatever')。また、前述のように、使用しているKohanaのバージョンを知っておくと便利です。 – badsyntax

答えて

1

ザッツ私はテンプレートのコントローラーを使用する方法、それに役立つことを願っています:

<?php defined('SYSPATH') or die('No direct script access.'); 

class Controller_Template_Default extends Controller_Template 
{ 
    public $template = 'templates/default'; 

    protected $auth; 

    protected $user; 

    public function before() 
    { 
     parent::before(); 

     Session::instance(); 

     $this->auth = Auth::instance();  

     if (($this->user = $this->auth->get_user()) === FALSE) 
     { 
      $this->user = ORM::factory('user'); 
     } 

     if($this->auto_render) 
     { 
      $this->template->title   = ''; 
      $this->template->meta_keywords = ''; 
      $this->template->meta_description = ''; 
      $this->template->meta_copywrite = ''; 
      $this->template->header   = ''; 
      $this->template->content   = ''; 
      $this->template->footer   = ''; 
      $this->template->styles   = array(); 
      $this->template->scripts   = array(); 
      $this->template->bind_global('user', $this->user); 
     } 
    } 

    public function after() 
    { 
     if($this->auto_render) 
     { 
       $styles     = array('css/default.css' => 'screen', 'css/reset.css' => 'screen'); 
       $scripts     = array('js/infieldlabel.js', 'js/menu.js', 'js/jquery.js'); 

       $this->template->styles = array_reverse(array_merge($this->template->styles, $styles)); 
       $this->template->scripts = array_reverse(array_merge($this->template->scripts, $scripts)); 
      } 

     parent::after(); 
    } 
} // End Controller_Template_Default 

P.S.コンテンツに定数を使用しないでください。 コントローラをController_TEemplate_Defaultから拡張し、$ this-> template-> content = View :: factory( 'viewへのパス')のようにバインドします。

関連する問題