-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