我正在开发Cakephp 2.3 ..这是我的代码
class MessagesController extends AppController{
public $helpers = array('Time');
public function messages(){
$datetime= $this->Message->getDatetime($userid); //$datetime = 2013-06-14 10:28:00
$time = $this->Userinfo->getTimeZone($userid); //$time = 5.00
$finaltime = $this->Time->format('Y-m-d H:i:s', $dateTime, NULL, $time);
出口();
}
它正在给我
Fatal error: Call to a member function format() on a non-object
有谁知道我做错了什么?
答案 0 :(得分:0)
问题在于,仅仅因为你在控制器中使用$ helper并不意味着它是可访问的。它实际上是传递给视图或.ctp文件。
// called as CakeTime
App::uses('CakeTime', 'Utility');
echo CakeTime::format('2011-08-22', '%d-%m-%Y');
参考:http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#TimeHelper::format