問題描述
我的數(shù)據(jù)庫中只有一個名為ficha_seg"的表.我的模型文件名為Ficha.php",控制器名為FichasController.php".
那么,為什么我會收到錯誤:
錯誤:在默認數(shù)據(jù)源中找不到模型 Ficha 的表 fichas.
像這樣配置我的控制器的 index() 方法后:
公共函數(shù) index() {$this->set('ficha_seg', $this->Ficha->find('all'));}
默認情況下,模型使用模型類名的小寫復(fù)數(shù)形式作為數(shù)據(jù)庫表名.
如果你需要為你的模型使用另一個表名,你可以使用useTable
屬性:
class Ficha 擴展 AppModel{公共 $useTable = 'ficha_seg';}
參見 http://book.cakephp.org/2.0/en/models/模型屬性.html#usetable和Cookbook 中的模型約定>
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'));
}
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
這篇關(guān)于在默認數(shù)據(jù)源中找不到模型的 cakephp 表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!