2
votes

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.

1
debug(get_class($this->Agent)) - it's not your class, because the model filename is wrong. It's a better idea to use uses 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

1 Answers

0
votes

Rename files

agent.php -> Agent.php
airtime.php -> AirTime.php
agentController.php -> AgentController.php

Source: http://book.cakephp.org/2.0/en/getting-started/cakephp-conventions.html#file-and-class-name-conventions