Search code examples
cakephpmodels

How to access non-child models from other controller in CakePHP?


I'm having trouble finding information about how to use a model that doesn't belong to the current controller.

For example: I have an ajax controller that sends only JSON data to application. This controller needs to access different models depending on request.

How do I do this?


Solution

  • 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');
    }
    ?>