本文介绍了Cakephp致命错误:在非对象上调用成员函数format()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发Cakephp 2.3 ..这是我的代码
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();
}
它给了我
Fatal error: Call to a member function format() on a non-object
$上调用成员函数format() b
$ b
有人知道我在做什么错吗?
anybody know what i am doing wrong?
推荐答案
问题是,仅仅因为您在控制器中使用$ helper并不意味着它可以访问。它实际上正在传递给视图或.ctp文件。
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');
参考:
这篇关于Cakephp致命错误:在非对象上调用成员函数format()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!