[英]How to render 2 views of different actions of different controllers in Zend 1.11
[英]Site Wide Class for Zend that can be used in actions, controllers and views?
如何創建站點范圍的功能,以根據ID獲得角色或區域。 另外,在視圖中還可以根據(實際/目標)的計算返回特定的顏色。 我想在視圖和動作中使用它。
我已經嘗試過,創建一個類並在庫中進行設置:
class Colouring
{
/*
* Array of the class for specifically the GEP portal theme
*/
private $colours_class = array( 0 => 'color-grey',
1 => 'color-grey',
2 => 'color-orange',
3 => 'color-blue',
4 => 'color-green'
);
/*
* Returns colour based on actual and target
*/
private static function getColour($actual, $target)
{
...return someValue
}
}
路徑: Zend_Site/library/
我得到錯誤:
Fatal error: Class 'Colouring' not found in
因此,我以為也許需要View_Helper:
因此,我將路徑更改為: My/View/Helper/Colouring.php
,將類更改為: My_View_Helper_Colouring
將其添加到config.ini: resources.view.helperPath.My_View_Helper_ = "My/View/Helper/"
我用:
$viewHelperObj = $this->view->getHelper('Colouring');
$viewHelperObj->getColour($this->value, $this->divisor);
給定: Fatal error: Call to a member function getHelper() on a non-object
我也嘗試過:
$this->getColour($this->value, $this->divisor);
這使:
Plugin by name 'GetColour' was not found in the registry
因此,並沒有真正獲得用於在站點范圍內甚至為站點范圍內的類和注冊方式添加靜態方法的正確方法的想法。 我會使用插件,View幫助器,Action幫助器還是只是上課。
我正在使用Zend 1。
首先,您必須將方法重命名: getColour()
to Colouring()
getColour()
to Colouring()
並將其公開。 然后嘗試從這樣的視圖調用它:
echo $this->Colouring('biz', 'bazz');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.