Kvothe
Kvothe

Reputation: 1837

Can CakePHP model names contain numbers?

I have a model called Stage1Application and a corresponding controller called Stage1ApplicationsController.

In the controller when I use

$this->Stage1Application->create();

I get "called create on non-object" error. Is this because I have numbers in the names of my model/controller?

I also have the line

public $uses = array('Package','PersonalDetail','MarriageDetail','ChildrenDetail');

at the beginning of my controller - is this stopping it from including its own model? If this is the problem then how do I make the $uses array append - so that the model for the current controller is included by default?

Upvotes: 0

Views: 151

Answers (2)

Kai
Kai

Reputation: 3823

I'm not aware of any limitations to model names other than they must be a valid class name. From PHP's manual: A valid class name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. http://php.net/manual/en/language.oop5.basic.php So, numbers should be allowed, as long as you don't start with a number.

And yes, if you declare $uses, it overwrites the default $uses property. Either add Stage1Application to your $uses property declaration:

public $uses = array('Package','PersonalDetail','MarriageDetail','ChildrenDetail', 'Stage1Application');

Or, you can alter your $uses property in the controller's beforeFilter function and have the models still load:

$this->uses = array_merge($this->uses, array('Package','PersonalDetail','MarriageDetail','ChildrenDetail'));

Upvotes: 2

floriank
floriank

Reputation: 25698

You don't have the Stage1 model in your uses array, that is why you get that error.

Upvotes: 1

Related Questions