php - CakePHP 3.6.11:从另一个控制器在 ctp 中创建下拉菜单
问题描述
我有customers
(id, name) 和services
(id, title, isSubscription),我想在其中添加一个下拉列表add.ctp
,Customers
其中将包含所有titles
的Services
where isSubscription
is true
。我怎样才能做到这一点?
Customers
和之间没有关系Services
,它只会用特定客户和所选服务的customerServices
(customerid, serviceid) 表填充。id
id
这是我尝试过的:
在ServicesController.php
中add function
:
$services = $this->Services->find('list'); //the error is here because there is no relationship between Customers and Services
$this->set(compact('services'));
在add.ctp
中Template/Customers
:
$this->Form->control('category',array('options' => $services));
但我明白了:
在布尔值上调用成员函数 find()
解决方案
该文档包含一个标题为“获取表类实例”的部分,它准确地显示了您需要的内容:
TableRegistry::getTableLocator()->get('Services')->find(...)
推荐阅读
- python-3.x - 如何在程序结束时关闭python进程
- spring - 使用 Hibernate JPA 处理工作单元的问题
- sockets - 带有raspberrypi的android设备的蓝牙通信-连接被拒绝时出现错误
- c - 子进程和父进程之间的同步 c
- typescript - Typescript 中的字符串验证
- node.js - 软件包在 NMP 安装时被删除
- javascript - 如何使用 Vue.js 下载图像而不显示它们?
- python - 序列化程序调用显示 TypeError:“ListSerializer”类型的对象不是 JSON 可序列化的?
- vuejs2 - 实现:无法在 Dropdown._makeDropdownFocusable 处设置属性“tabIndex”为空
- swift - 如何获取 MacOS Xcode 项目中使用的 sparkle 框架的当前版本