Question

how can i access method $this->someModel->find('all') when im in different model form example:

class DevicesController extends AppController {
     public function add(){
         $departments = $this->Department->find('all', array(
            'fields'     => array('id', 'mac')
     ));
     $this->set(compact('departments'));

    .....
    .....
}

right now there is error because $this doesn't "see" Department

what i need to do to make it happen.

Was it helpful?

Solution 2

If models are not related, try this way:

$this->loadModel('Department');
$departments = $this->Department->find('all', array(
            'fields'     => array('id', 'mac')
     ));
$this->set(compact('departments'));

OTHER TIPS

If the models are in fact related (and properly set up so in the models), it would be

$this->Device->Department->...

otherwise use loadModel() as documented.

u can't just use loadModel() because it is controller's method. if your models aren't related u can do this like that

$this->ModelName = ClassRegistry::init('ModelName');
$this->ModelName->find...

if they are related just use

$this->ModelName->find...

Try this code for loading different models on a controller. public $uses = array('ModelName1', 'ModelName2') $this->ModelName1->find()........

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top