2016-11-17 81 views
0

我在ZF 1.12.x項目的工作,我將保存在新的自定義幫助:/application/views/helpers/MyFormText.php(也試圖與名稱View_Helper_MyFormText):在Zend Framework 1中註冊自定義助手的正確方法是什麼?

助手的內容至今也很簡單:

class MyFormText extends Zend_View_Helper_FormText 
{ 
    public function MyFormText($name, $value = null, $attribs = null) 
    { 
     // @TODO: check if the component can be rendered on the view 
     return parent::formText($name, $value, $attribs); 
    } 
} 

當我訪問我這個錯誤結束頁:

[message:protected] => Plugin by name 'MyFormText' was not found in the registry; used paths: Zend_View_Helper_: Zend/View/Helper/:./../application/views/helpers/

是奇怪的,顯然這條道路:

Zend_View_Helper_: Zend/View/Helper/:./../application/views/helpers/ 

用於尋找幫助者,但即使該類無法加載。我已閱讀並嘗試了所有的這些:

我做錯了嗎?任何人都可以給我一些幫助嗎?我被卡住了

+0

嘗試打印輔助路徑/ s。從視圖來看,你可以var_dump($ this)。你可以使用'Zend_View :: addHelperPath'註冊路徑。 – Progrock

+0

@Progrock我沒有看到加載的路徑,所以可能沒有註冊。儘管我可以在Zend_View_Helper_:Zend/View/Helper /:./../ application/views/helpers /'錯誤處看到它。你能爲我寫一個小例子嗎? – ReynierPM

+1

在application.ini - >'resources.view.helperPath.Your_View_Helper_Class_Prefix = APPLICATION_PATH「/ views/helpers」' – Progrock

回答

0

我找到了我的答案here

By default, the class is prefixed with 'Zend_View_Helper_' (you can specify a custom prefix when setting a helper path), and the last segment of the class name is the helper name; this segment should be TitleCapped; the full class name is then: Zend_View_Helper_FooBar. This class should contain at the minimum a single method, named after the helper, and camelCased: fooBar().

所以從MyFormText改變類名Zend_View_Helper_MyFormText使其向作品。

相關問題