我正在使用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');
}
?>
答案 0 :(得分:0)
HEHA :)内部控制器
public $name= 'Trips';
是正确的你有Trip
,记住控制器使用复数名称。
同样模型文件名=&gt; Trip.php
答案 1 :(得分:-1)
尝试: -
public $ uses = array('Trip');
在你的控制器中