Reputation: 725
I have been having a problem lately with my CakePHP models. The capitalization of the first letter of the model name keep changing. For example
$brands = $this->brand->findAllByCompanyId($company);
$list = array();
foreach ($brands as &$brand) {
$list[] = array(
'name' => $brand['brand']['name'],
'id' => $brand['brand']['id']
);
}
For some reason, the key names would change to
$brand['Brand']['name']
$brand['Brand']['id']
Notice the change in the capitalization in the word "Brand." Does anyone have an idea why this happens, or how to force a specific capitalization?
Upvotes: 1
Views: 1220
Reputation: 12863
One of the basic principles of CakePHP is about making life easier by following conventions. As @Neal above says, CakePHP expects the Model to be capitalised. Stick to it being capitalised and you'll make your life easier.
Upvotes: 2
Reputation: 3462
You can override this by adding the line in your model
.
$this->name = 'brand';
Upvotes: 1
Reputation: 146360
CakePHP models always capitalizes the name of the model when it is selecting it from the database.
(I am assuming that $this->brand->findAllByCompanyId($company);
is doing a query)
Upvotes: 1