在另一个控制器视图中列出表单模板

Listing Form Templates within another Controller view

我有一个 form_templates table 和一个表格 table。他们通过 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'));
}

但是我收到一个调用成员函数 find() 的空错误。

如能提供解决此问题的任何帮助,我们将不胜感激。我知道这很简单,但我是 cakephp 的新手。

在您的 FormsController 中,只有 FormsTable 自动加载,而您正在尝试访问当前未加载的模型:

$formTemplate = $this->FormTemplates->Forms->find(...

要得到你想要的,你应该像这样访问关联的FormTemplatesTable

$formTemplate = $this->Forms->FormTemplates->find(...