我的数据库中只有一个名为“ficha_seg”的表。 我的模型文件的名称是“Ficha.php”, Controller 的名称是“FichasController.php”。
所以,为什么我会收到错误:
Error: Table fichas for model Ficha was not found in datasource default.
像这样配置我的 Controller 的 index() 方法后:
public function index() {
$this->set('ficha_seg', $this->Ficha->find('all'));
}
最佳答案
默认情况下,模型使用模型类名的小写复数形式作为数据库表名。
如果你需要为你的模型使用另一个表名,你可以使用useTable
属性:
class Ficha extends AppModel
{
public $useTable = 'ficha_seg';
}
参见 http://book.cakephp.org/2.0/en/models/model-attributes.html#usetable 和 Model conventions在食谱中
关于php - 在数据源默认值中找不到模型的 cakephp 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13511136/