我使用CakePHP和我得到了以下错误:调用一个成员函数查找()一个非对象
Error: Call to a member function find() on a non-object
File: C:\xampp\htdocs\project\app\Controller\TripsController.php
Line: 12
Tripscontroller.php代码:
<?php
class TripsController extends AppController{
public $name= 'Trip';
public function index($City=null){
$trips = $this->Trip->find('all');
$this->set('trips',$trips);
$cities = $this->Trip->City->find('all');
$this->set('cities',$cities);
}
}
我已经已关 “trips.php” 里面的两个对象:
<?php
class Trip extends AppModel
{
public $name= 'Trip';
public $belongsTo= array('City');
}
?>
您需要添加一个'__construct()'函数和给予'$ this' – iatboy 2014-10-04 02:20:58
http://book.cakephp.org/2.0/en/getting-started /cakephp-conventions.html#file-and-class-name-conventions,http://book.cakephp.org/2.0/en/controllers.html#Controller::$name – ndm 2014-10-04 02:22:27
什么是 “trips.php”?这不符合任何惯例。 – Dave 2014-10-04 20:35:18