2013-08-05 62 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

相關問題