私はこのテーブルを持っています:
顧客[ID、名前、姓、電話番号、テキスト、残高、作成済み]
service_types [id、title、price、length、is_subscription、created]
customer_service_types [id、customer_id、service_type_id、price、created]
でview.ctp
、私はすべて見たいと思ってServices
、現在の顧客に割り当てられています。
Bake
でこれview function
を作成しましたCustomersController.php
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>
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加