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.




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.
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?
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…
@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.
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.
Thanks Troy, the concept of an admin panel makes perfect sense to me.
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?
[...] Related post: A controller without a model [...]