I am having trouble with CakePHP
The Agent Model: agent.php
class Agent extends AppModel{
var $name = 'Agent';
var $belongsTo = array(
'Arrival'=>array(
'className'=>'AirTime',
'foreignKey'=>'arrival_id'
),
'Departure'=>array(
'className'=>'AirTime',
'foreignKey'=>'departure_id'
));
}
The Airtime Model: airtime.php
class AirTime extends AppModel{
var $name = 'AirTime';
}
Controller: agentController.php
$condition = array(
'limit'=>20,
'contain'=>array(
'Arrival'=>array(
'fields'=>array('airline_id','flight_num'),
'Airline'=>array('fields'=>'code')
),
'Departure'=>array(
'fields'=>array('airline_id','flight_num'),
'Airline'=>array('fields'=>'code')
)
)
);
$this->Agent = ClassRegistry::init('Agent');
$this->paginate=$condition;
$data = $this->paginate('Agent');
When I run it I get the following errors:
Warning (512): Model "Agent" is not associated with model "Arrival" [CORE/cake/libs/model/behaviors/containable.php, line 343]
Warning (512): Model "Agent" is not associated with model "Departure" [CORE/cake/libs/model/behaviors/containable.php, line 343]
I do not know how to solve this problem and would like some help.
debug(get_class($this->Agent))
- it's not your class, because the model filename is wrong. It's a better idea to useuses
or loadModel in a controller. If this is in your Agents controller$this->Agent
would be loaded by default. Generally, using the bake cli script avoids these problems. – AD7six