CakePHP 3.6.11:访问视图中的连接表 属性
CakePHP 3.6.11: Access property of joined tables in view
我有这个表:
customers[id, name, surname, phone, text, balance, created]
service_types[id, title, price, length, is_subscription, created]
customer_service_types[id, customer_id, service_type_id, price, created]
在 view.ctp
中,我想查看分配给当前客户的所有 Services
。
Bake
在 CustomersController.php
中创建了这个 view function
public function view($id = null)
{
$customer = $this->Customers->get($id, [
'contain' => ['CustomerServiceTypes']
]);
$this->set('customer', $customer);
}
在 view.ctp
中,我想显示 service_type -> title
所以我是这样尝试的:
<td><?=$customerServiceTypes->service!==null ? h($customerServiceTypes->service->title) : '' ?></td>
但是总是显示空白。我该如何更改它才能正常工作?
修改视图函数如下:
$customer = $this->Customers->get($id, [
'contain' => ['CustomerServiceTypes' => ['ServiceTypes']]
]);
$this->set('customer', $customer);
在view.ctp中:
<td><?= h($customerServiceTypes->service_type->title) ?></td>
我有这个表:
customers[id, name, surname, phone, text, balance, created]
service_types[id, title, price, length, is_subscription, created]
customer_service_types[id, customer_id, service_type_id, price, created]
在 view.ctp
中,我想查看分配给当前客户的所有 Services
。
Bake
在 CustomersController.php
view function
public function view($id = null)
{
$customer = $this->Customers->get($id, [
'contain' => ['CustomerServiceTypes']
]);
$this->set('customer', $customer);
}
在 view.ctp
中,我想显示 service_type -> title
所以我是这样尝试的:
<td><?=$customerServiceTypes->service!==null ? h($customerServiceTypes->service->title) : '' ?></td>
但是总是显示空白。我该如何更改它才能正常工作?
修改视图函数如下:
$customer = $this->Customers->get($id, [
'contain' => ['CustomerServiceTypes' => ['ServiceTypes']]
]);
$this->set('customer', $customer);
在view.ctp中:
<td><?= h($customerServiceTypes->service_type->title) ?></td>