CakePHP调用非对象上的成员函数 [英] CakePHP call to member function on non-object

查看:94
本文介绍了CakePHP调用非对象上的成员函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下模型和控制器文件,当我访问这个网址, http://....../pois/index 我得到这个错误:

I have the following Model and Controller files, and when i visit this url, http://....../pois/index i get this error:

注意(8):未定义属性:PoisController :: $ Poi [APP / controllers / pois_controller.php,line 5] c $ c>

Notice (8): Undefined property: PoisController::$Poi [APP/controllers/pois_controller.php, line 5]

致命错误:调用/ home / joecoyle / public_html / app中非对象的成员函数find /controllers/pois_controller.php on line 5

模型是这样的,叫做 poi.php

<?php
class Poi extends AppModel {

}
?>

而控制器就是这样,命名为 pois_controller.php

And the controller is this, named pois_controller.php

<?php
class PoisController extends AppController {

    function index(){
            $this->set('pois',$this->Poi->find('all'));
    }
}
?>

由于我是CakePHP的新手,我不知道是什么原因导致这个错误,因为一切似乎命名,正确,我遵循CakePHP网站上的教程...

As i am new to CakePHP i am not sure what is causing this error, as everything seems to be named, right, and i am following the tutorial on the CakePHP site...

感谢

推荐答案

如果SpawnCxy的解决方案没有做这项工作(我自己的控制器将 name 属性设置为多元化版本,采取),看看拐点。 Poi不是一个常见的字,一个快速测试告诉我,CakePHP 1.2.6不处理这个词你想象的方式:

If SpawnCxy's solution doesn't do the job (my own controllers set the name property to the pluralized version rather than the singular variation that the model takes), take a look at the inflection. "Poi" isn't a "common" word and a quick test tells me that CakePHP 1.2.6 doesn't handle this word the way you're thinking it will:

echo '<p>' . Inflector::singularize( 'Pois' ) . '</p>'; # prints "Pois"
echo '<p>' . Inflector::pluralize( 'Poi' ) . '</p>';    # prints "Pois"

这一点当然是,Cake可能不会正确关联 PoisController (复数)和 Poi 模型。

The point of this, of course, is that Cake may not be making the correct association between the PoisController (plural) and the Poi model (singular) the way it does for most common English names.

这篇关于CakePHP调用非对象上的成员函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆