2013-08-05 63 views
0

我是一个CakePHP的2.3工作..这里是我的代码CakePHP的致命错误:调用一个成员函数的格式()非对象

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

问题是,仅仅因为您在控制器中使用$ helper并不意味着它是可访问的。它实际上是传递给视图或.ctp文件的geting。

// 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

+0

不能正常工作......给错误 – hellosheikh

+0

这是否给出相同的错误之前? – Sixthpoint

+1

此问题已被解决,但为cakephp的不同版本:http://stackoverflow.com/questions/1779176/cakephp-time-helper-problem – Sixthpoint

相关问题