Cakephp Fatal error: Call to a member function format() on a non-object

橙三吉。 提交于 2019-12-11 22:57:41

问题


i am working on a Cakephp 2.3 .. here is my code

  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);

exit();

}

it is giving me

Fatal error: Call to a member function format() on a non-object

anybody know what i am doing wrong?


回答1:


The problem is that just because you are using the $helper in the controller doesn't mean it is accessible. It is actually geting passed to the view or .ctp file.

// called as CakeTime
App::uses('CakeTime', 'Utility');
echo CakeTime::format('2011-08-22', '%d-%m-%Y');

Reference: http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#TimeHelper::format



来源:https://stackoverflow.com/questions/18065086/cakephp-fatal-error-call-to-a-member-function-format-on-a-non-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!