コントローラにテンプレート定義Piotrがありません。
コントローラで行う必要があるのは、コントローラが使用する必要のあるビューを定義することです。
class Controller_Start extends Controller_Template {
// This has to be defined
public $template = 'start';
public function action_index()
{
$this->template->set('title', array('tytul 1', 'tytul 2'));
// No need to do this if you're extending Controller_Template
// $this->response->body($view);
}
}
my_view
フォルダにあるテンプレートファイルのファイル名(.php拡張子なし)です/application/views
。サブフォルダにある場合は、そこに入力します。例:
public $template = 'subfolder/start';
メソッドはそれをViewオブジェクトController_Template::before()
に変換するため、文字列として定義する必要があることに注意してください。これは、デフォルトのオブジェクトをオーバーライドする場合を除いて、内に独自のオブジェクトを作成する必要がないことを意味します。次に、次のようなことを行う必要があります。$view
action_index()
class Controller_Start extends Controller_Template {
public function action_index()
{
$view = View::factory('start')
->set('title', array('tytul 1', 'tytul 2'));
$this->template = $view;
// And that's it. Controller_Template::after() will set the response
// body for you automatically
}
}
テンプレートを完全に制御したいが、コハナに干渉させたくない場合は、Controller_Template
クラスを拡張せずに、プレーンController
を使用してビューを自分でレンダリングすることをお勧めします。例:
class Controller_Start extends Controller {
public function action_index()
{
$view = View::factory('start')
->set('title', array('tytul 1', 'tytul 2'));
// Render the view and set it as the response body
$this->response->body($view->render());
}
}