Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cakephp Table for model was not found in datasource default

Tags:

php

mysql

cakephp

I have just a table on my database named "ficha_seg". The name of my model file is "Ficha.php" and the name of the controller is "FichasController.php".

So, why i'm getting the error:

Error: Table fichas for model Ficha was not found in datasource default.

after configured my index() method of controller like this:

 public function index() {
    $this->set('ficha_seg', $this->Ficha->find('all'));
}
like image 831
user1511579 Avatar asked Nov 22 '12 10:11

user1511579


2 Answers

By default, the model uses the lowercase, plural form of the model’s class name for the database table name.

If you need to use another table name for your model, you can use the useTable attribute:

class Ficha extends AppModel 
{
    public $useTable = 'ficha_seg';
}

See http://book.cakephp.org/2.0/en/models/model-attributes.html#usetable and Model conventions in the Cookbook

like image 52
nIcO Avatar answered Oct 02 '22 18:10

nIcO


To follow CakePHP conventions your table name should be in plural: ficha_segs and your model name should be 'FichaSeg'.

If you don't want to follow it for any reason, do what @nlcO says.

like image 41
Alvaro Avatar answered Oct 02 '22 18:10

Alvaro