我试图从数据库中获取客户端名称但是有错误说明了 “试图获得非对象的属性”
索引中的代码行如下所示
$this->Html->link( $camp->client->name,['controller' => 'Clients', 'action' => 'view', $camp->id]);
这是控制器
public function index($id = null) {
$client = $this->Camps->Clients->find()->where(['Clients.id' => $camp['client_id']])->first();
debug($client);
if ($id != null) {
$query = $this->Camps->find('all')->where(['client_id' => $id]);
$this->set('camps', $this->paginate($query));
$client = $this->Camps->Clients->get($id);
} else {
$query = $this->Camps->find('all');
$this->set('camps', $this->paginate($query));
$client = $this->Camps->Clients->find('all')->toArray();
}
}