tags:

views:

290

answers:

3

Hey folks, i got trouble finding information about how to use model that doesnt belong to controller.

Lets see, for example: i have ajax controller, that performs only JSON data to application, and it supposed to access different models depending on request.

So, how can i do it ?

+2  A: 

Check out the Manual section titled $components, $helpers and $uses, you are looking for $uses:

<?php
class RecipesController extends AppController {
var $name = 'Recipes';
var $uses = array('Recipe', 'User'); // both models will be available
var $helpers = array('Ajax');
var $components = array('Email');
}
?>
Paolo Bergantino
+2  A: 

$uses causes performance hit. Better way is:

$User = ClassRegistry::init('User');
$User->find(...);
evilbloodydemon
A: 

If the Recipe and User models are related you could do something like:

$this->Recipe->User->find(....);
jimiyash