Friends, I am displaying a user’s profile along with the products registered by him. My relationships are correct. I can list all products as normal, along with user information. But my product search field in the user’s view doesn’t work.
This is my code detail_user.ctp
//user information only above. (Address, Telephone, etc.)
.
.
.
<h2 class="bd-title mt-2" id="content">Products Gallery</h2>
<div class="card mt-2 mb-2">
<div class="card-header">
<?= $this->Form->create('', ['type' => 'get']); ?>
<div class="input-group">
<?= $this->Form->control('keyword', array('class' => 'form-control','name'=> 'search','label' => false,'required' => true,));?>
<div class="input-group-append">
<?= $this->Form->button(__('Search')); ?>
</div>
</div>
</div>
<div class="table-responsive">
<table class="table table-hover">
<tbody>
<?php foreach ($user->products as $product): ?>
<td>
<p class="title mb-0"><?= h($product->name) ?> </p>
<var class="price text-muted">R$ <?= number_format($product->price);?></var>
</td>
<td> <br></td>
<td width="130">
<?= $this->Html->link(__('Open'), ['controller' => 'Produtos','action' => 'details_product','prefix' => false, $product->slug], array('class' => 'btn btn-primary')) ?>
</td>
</tr>
<?php endforeach; ?>
</tbody></table>
</div> <!-- table-responsive .end// -->
</article>
And my method is like this:
public function detailUser($slug)
{
$keyword = $this->request->getQuery('keyword');
$this->paginate = [
'contain' => ['Products'],
'conditions' => ['product_name like' => '%'. $this->request->getQuery('keyword') . '%']
];
$usuario = $this->Users
->findBySlug($slug)
->contain(['Products', 'Groups'])
->firstOrFail();
$query = $this->Users->find('all');
$this->set('user', $user);
$this->set('query', $this->paginate($query));
}
I have difficulties to solve this method. At the moment, when I type the product name, the url changes, but the product is not searched.I get the error: Column not found: 1054 Unknown column ‘product_name’ in ‘where clause’
I also tried:
'contain' => ['Products.Users'],
But the error continues.
I appreciate any comments!