CakePHP 3.0从数据库中检索记录

时间:2016-06-07 18:45:27

标签: php cakephp cakephp-3.0

我试图从数据库中获取客户端名称但是有错误说明了 “试图获得非对象的属性”

索引中的

代码行如下所示

 $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();
    }
}

0 个答案:

没有答案