5

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'));
}
4

2 回答 2

24

默认情况下,模型使用模型类名的小写复数形式作为数据库表名。

如果你需要为你的模型使用另一个表名,你可以使用useTable属性:

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

请参阅http://book.cakephp.org/2.0/en/models/model-attributes.html#usetable 和Cookbook 中的模型约定

于 2012-11-22T11:20:06.737 回答
5

为了遵循 CakePHP 的约定,你的表名应该是复数形式:ficha_segs并且你的模型名应该是 'FichaSeg'。

如果您出于任何原因不想关注它,请按照@nlcO 所说的去做。

于 2012-11-22T11:22:59.873 回答