Zend_Viewを触ってみる
$this->_viewで色々設定できるらしー。
■パスの指定
class IndexController extends Zend_Controller_Action
{
public function init()
{
$this->_session = new Zend_Session_Namespace('global');
$this->view->module = $this->_getParam('module');
$this->view->controller = $this->_getParam('controller');
$this->view->action = $this->_getParam('action');
}
public function indexAction()
{
// view 関連のディレクトリのパス(helpers,filters,scriptsが含まれる)
$this->view->setBasePath('../views');
// filters関連のディレクトリのパス
$this->view->setFilterPath('../views/filters');
// helpers関連のディレクトリのパス
$this->view->setHelperPath('../views/helpers');
// scripts関連のディレクトリのパス
$this->view->setScriptPath('../views/scripts');
// view 関連のディレクトリのパス(helpers,filters,scriptsが含まれる)
$this->view->addBasePath('../views');
// filters関連のディレクトリのパス
$this->view->addFilterPath('../views/filters');
// helpers関連のディレクトリのパス
$this->view->addHelperPath('../views/helpers');
// scripts関連のディレクトリのパス
$this->view->addScriptPath('../views/scripts');
$this->view->title = 'ページのタイトル';
}
}
■エンコードとエスケープ
ガラパゴス携帯だからsjisとか。
class IndexController extends Zend_Controller_Action
{
public function init()
{
$this->_session = new Zend_Session_Namespace('global');
$this->view->module = $this->_getParam('module');
$this->view->controller = $this->_getParam('controller');
$this->view->action = $this->_getParam('action');
}
public function indexAction()
{
$this->view->encoding('Shift_JIS');// 文字コードを指定
$this->view->escape('htmlentities');// escapeで使う関数を指定
$this->view->title = 'ページのタイトル';
}
}
■フィルタ
class IndexController extends Zend_Controller_Action
{
public function init()
{
$this->_session = new Zend_Session_Namespace('global');
$this->view->module = $this->_getParam('module');
$this->view->controller = $this->_getParam('controller');
$this->view->action = $this->_getParam('action');
}
public function indexAction()
{
$this->view->setFilter('hogeFilter');
$this->view->title = 'ページのタイトル';
}
}
views/filters配下に設置。
class Zend_Filter_HogeFilter extends Zend_Filter
{
public function filter($value)
{
$value = preg_replace('/<p>/', '<p><i>', $value);
return $value;
}
}
■ヘルパー
よく使われる要素のビューヘルパはZend Frameworkで標準的に準備されてるらしー。
フォーム
第三引数でフォームの内容を指定できる。falseを指定すると開始タグしか出力されない。
<?php
echo $this->form(
'form',
array(
'action' => '/index/register',
'method' => 'post'
),
$this->formText('dateTime', '', array('size' => '30')) .
$this->formSubmit('', $this->translate('submit'))
);
?>
URL
有用性が良く分からん。
<?php
echo $this->url(array(
'controller' => 'Index',
'action' => 'index'
));
?>
TrackBack URL :
Comments (0)
コメントはまだありません»
コメントはまだありません。
この投稿へのコメントの RSS フィード。TrackBack URL
コメントする