CakePHP 3.6.11:从另一个控制器在 ctp 中创建下拉菜单

CakePHP 3.6.11: create dropdown in ctp from another controller

我有customers(id,name)和services(id,title,isSubscription),我想在[=15=的add.ctp中添加一个下拉列表] 将包含 Services 的所有 titles,其中 isSubscriptiontrue。我怎样才能做到这一点?

CustomersServices 之间没有关系,它只会填充 customerServices (customerid, serviceid) table 和 id特定客户和所选服务的 id

这是我尝试过的:

ServicesController.phpadd function:

$services = $this->Services->find('list'); //the error is here because there is no relationship between Customers and Services
$this->set(compact('services'));

add.ctpTemplate/Customers 中:

$this->Form->control('category',array('options' => $services));

但我明白了:

Call to a member function find() on boolean

该文档包含一个标题为 Getting Instances of a Table Class 的部分,它准确地显示了您需要的内容:

TableRegistry::getTableLocator()->get('Services')->find(...)