Url
を変数として渡し$url
、 を使用してビュー内でアクセスできる必要があります{$url->test()}
。ただし、静的関数にアクセスできるかどうかはわかりませんUrl::test()
。
同じビューでヘルパーを使用している場合は、ビューで変数をバインドする新しいコントローラーを作成できます。
<?php
// application/classes/controller/site.php
class Controller_Site extends Controller_Template
{
public $template = 'smarty:my_template';
public function before()
{
$this->template->set_global('url_helper', new Url);
}
}
?>
次に、他のコントローラーでそれを拡張します。
<?php
// application/classes/controller/welcome.php
class Controller_Welcome extends Controller_Site
{
public function action_index()
{
$this->template->content = 'Yada, yada, yada...';
}
}
ビュー内でアクセスします。
{* application/views/my_template.tpl *}
<p>This is a {$url_helper->test()}.</p>
<p>{$content}</p>