-2
我正在使用名爲ZosoHelper的自定義幫助器。我使用名爲get_relative_time
的函數來格式化給定的日期。我有另一個功能,在同一個ZosoHelper中調用get_month
,我想在我的get_relative_time
函數中訪問它。但我無法讓它工作。CakePHP幫助函數使用其他函數(在同一個幫助器中)
我試過這樣的事情:(修剪 - 只爲邏輯)
class ZosoHelper extends AppHelper {
function get_month(){
$month = "januari";
return $month;
}
function get_relative_time(){
$date = $this->Zoso->get_month();
//Note: I also tried $this->get_month();
return $date;
}
}
我打消了我所有的代碼,以保持它的簡單。我只想在我的新get_relative_time
函數中調用我的其他函數(get_month
)。
'$ this-> get_month()'應該可以工作 – arilia
Basic OOP PHP。順便說一句,你應該遵循CakePHP的編碼約定。方法是駝背,並始終具有可見性(公開...)。 – mark
你的評論說「注意:我也試過$ this-> get_month();」這肯定應該工作。你有錯誤或通知? – Nunser