A controller without a model

If you want to create a controller which does not use a model, you have to create your controller in the following way:

// tested with CakePHP r1892
class MyController extends AppController
    // var $uses = null; works too
    var $uses = array();

    function index()

If you omit the “var $uses = array();” you will get a “missing model” error.



  1. Posted February 1, 2006 at 8:24 pm | Permalink

    What happens if you need to define the uses array so that this controller has access to others? That is why I have always done the $useTable = false; in the model for MVC’s that don’t have actual tables tied to them.

  2. Posted February 1, 2006 at 9:01 pm | Permalink

    As a newbie to CakePHP this is an interesting idea. Can you (or anyone) propose a concrete example where this would be beneficial to explain how this fits into the scheme of things?

  3. Posted February 1, 2006 at 9:54 pm | Permalink

    I wonder… I’ve got a Controller without any associated Model, I do not specify anything like $uses or such, and yet it just works without requesting any model…

  4. Posted February 2, 2006 at 9:38 am | Permalink

    @Troy: What do you mean with “if you need to define the uses array so that this controller has access to others”?

    @ChrisC: An example could be a simple static web presence without a database.

    @JMG: You are right, it works in the way you described in RC3. But you have to use $uses when using the latest version from trunk and in the coming RC4.

  5. Posted February 2, 2006 at 4:49 pm | Permalink

    I mean. I need to define $uses(‘Model1’, ‘Model2’, etc) So, I couldn’t use this method in that case as my $uses would actually be set to something. So, the method that works ALL the time is to setup the Model with the var $useTable = false;

    And static pages is a good example. Another good example is an administration panel. It doesn’t have it’s own table, but needs to access all the others. So, that is why $uses would need to be actually set to something and you would have to use what I described above.

  6. Posted February 2, 2006 at 4:56 pm | Permalink

    Thanks Troy, the concept of an admin panel makes perfect sense to me.

  7. Nate
    Posted February 2, 2006 at 5:16 pm | Permalink

    Troy: Sounds like you answered your own question. If you use the method above, then your controller will have no models. If you define $uses, and set it to an array of custom models, the controller will load those models and no others.

    So where’s the confusion?

  8. Posted September 29, 2009 at 7:55 am | Permalink

    I want to create a controller without a model with authentication features for user.. I am newbie in cakephp can you explain me how i can do that.

  9. Sujoy Pal
    Posted January 28, 2010 at 8:38 pm | Permalink

    Thank you very much. I was looking for this solution for last 30 minutes and digging my head on the desk. Thank u very much.

  10. Igor
    Posted April 28, 2011 at 2:56 am | Permalink

    Thanks for the tip. It was very helpful at the time I wrote this

Post a Comment

Required fields are marked *

%d bloggers like this: