【发布时间】:2018-09-18 03:55:26
【问题描述】:
我有一个 form_templates 表和一个 forms 表。它们通过 form_template_id 连接。我希望能够在我在 Forms 控制器中创建的 select.ctp 文件中列出按标题创建的 form_templates。只是想知道如何用 cakephp 做到这一点?
目前我的 FormsController 中有以下代码:
public function select()
{
$this->set('page_heading', 'Current Forms');
$contain = [];
$formTemplate = $this->FormTemplates->Forms->find('list', ['order' => 'title'])->where(['active'=>true]);
$forms = $this->paginate($this->Forms->FormTemplates);
$this->set(compact('forms', 'formTemplate'));
}
但我在 null 错误时收到对成员函数 find() 的调用。
任何有关如何解决此问题的帮助将不胜感激。我知道这很简单,但我是 cakephp 新手。
【问题讨论】:
-
在调用
$formTemplate = $this->FormTemplates->Forms->find('list', ['order' => 'title'])->where(['active'=>true]);之前加载模型($this->loadModel('FormTemplates'))。 -
感谢@Ishanvyas22,但我仍然收到相同的错误消息。
标签: cakephp orm cakephp-3.0