Cakephp致命错误:在非对象上调用成员函数format()

时间:2013-08-05 18:25:03

标签: cakephp datetime timezone cakephp-2.0 cakephp-2.1

我正在开发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

有谁知道我做错了什么?

1 个答案:

答案 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