zend library中,將所有View helper都儲存於views/helpers/內,所以我們也將自行建立的helper都儲存在這裏,因為view helper的預設path也是儲存在這裏。當然也可以使用setHelperPath()自行設定view helpers的path。
class Zend_View_Helper_MyHelper
{
protected $_view;
public function setView($view)
{
$this->_view=$view;
}
public function myHelper($var)
{
return $this->_view->escape($var):
}
}
{
protected $_view;
public function setView($view)
{
$this->_view=$view;
}
public function myHelper($var)
{
return $this->_view->escape($var):
}
}
setView 是一個interface,用於初始化view.
myHelper 是Helper的function,而例子中將會回傳過濾後的資料。
沒有留言:
張貼留言