tags:

views:

84

answers:

3

I am a beginning Cake user and trying to do some work on an already existing application. Running into a problem when I create a new controller. I have created StoreController and when I try to call methods inside it I get the error below. There is no table 'stores', but it seems like it's trying to automatically load a model relating to the controller. How can I prevent my application from trying to load a model for this controller?

Missing Database Table
Error: Database table stores for model Store was not found.
A: 

Think I found it...

class StoreController extends AppController {

// Do not preload any models, we will do this on demand to prevent waste.
var $uses = '';
Louis W
+4  A: 

Hi Louis,

That will do it, you can also just assign it to an empty array like so

var $uses = array();

Cheers, Dean

Dean
+1 - using an empty array is the correct approach. I remember problems with the empty string approach a while back, but that may have been fixed since then.
deizel
I had that issue with an empty string a while ago too, it will work now but it's better to safe than sorry!
Dean
A: 

If you have an AppController like so..

<?php
    Class AppController extends Controller {
        public $uses = array( 'GlobalModel' );
    }
?>

And you use an empty array...

<?php
    Class StoresController extends AppController {
        public $uses = array( );
    }
?>

Then the StoresController will still have access to the GlobalModel from the AppController

If you use

<?php
    Class StoresController extends AppController {
        public $uses = '';
    }
?>

Then the StoresController won't have access to ANY models.

A good amount of the time when someone wants a controller without a model, it is because they don't want to associate the controller with a database table. But for the purposes of making validation easier on submitted data etc what you might want to consider is

<?php
    Class StoresController extends AppModel {
        public $name = "Stores";
        public $uses = array( 'Store' );
    }
?>

<?php
    Class Store extends AppModel {
        public $name = "Store";
        public $useTable = false;
    }
?>

Then you can use the Model::_schema property. That is more than you asked for though, so I will let you do your own research on _schema and validating data that won't be handled by a DB table.

http://book.cakephp.org/view/442/_schema

Abba Bryant