I'm working with CakePHP now and I need to do a search with one view and then send the data to another action on the same controller, that will trigger another view with the results of that search. The thing is, on the search screen, there's also a table showing some data of the same model, and I believe that's one big problem. So right now, it's here what I got:
public function busca() {
$emergency = TableRegistry::get('EmergencySheets');
$manufacturers = TableRegistry::get('Manufacturers');
$data = $this->request->is('get') ? $this->request->query : $this->request->getData();
$query = $emergency->find()
->select(['id', 'data_atualizacao_fabricante', 'tarja', 'manufacturer_id', 'nome_comercial'])
->where('EmergencySheets.data_atualizacao_fabricante')
->order(['data_atualizacao_fabricante'=>'DESC'])
->limit(7);
$manufacturer_query = $manufacturers->find()
->select(['id','nome'])
->where($query->manufacturer_id = 'id');
$manufacturer = $manufacturer_query->toArray();
$sheets = $query->toArray();
$this->set('manufacturers', $manufacturer);
$this->set('sheets', $sheets);
if($data){
return $this->redirect(['action' => 'ficha' , $data]);
}else{
return $this->redirect(['action' => 'busca404']);
}
}
How can I handle this? Thank you all!
Edit: Forgot to mention, but the $data variable always come empty on the form, even when I type something on the form input. Here's the view code, too!
<section class="search-section">
<div class="container px-0">
<div class="search-wrapper">
<div class="search-title">
<h2><span>Quais produtos</span>você vai transportar?</h2>
<p><span>Pesquise pelos produtos no campo de busca</span>
ou clique nas letras ao lado.
</p>
</div>
<div class="search-bar">
<?=$this->Form->create()?>
<div class="ml-5 bar">
<input type="text" placeholder="Procure várias fichas de uma só vez" class="formcontrol tip"
data-toggle="tooltip" data-placement="top">
<span class="removeClick"><i class="fas fa-times-circle fa-2x"></i></span>
<button type="submit" class="btn"><i class="fa fa-search fa-2x"></i></button>
</div>
<?=$this->Form->end()?>
<div class="ml-5 alfabeto text-center">
<button href="#A">A</button> <button href="#B">B</button> <button href="#C">C</button> <button href="#D">D</button>
<button href="#E">E</button> <button href="#F">F</button> <button href="#G">G</button> <button href="#H">H</button>
<button href="#I">I</button> <button href="#J">J</button> <button href="#K">K</button> <button href="#L">L</button>
<button href="#M">M</button> <button href="#N">N</button> <button href="#O">O</button> <button href="#P">P</button>
<button href="#Q">Q</button> <button href="#R">R</button> <button href="#S">S</button> <button href="#T">T</button>
<button href="#U">U</button> <button href="#V">V</button> <button href="#W">W</button> <button href="#X">X</button>
<button href="#Y">Y</button> <button href="#Z">Z</button><button href="#0-9">0-9</button>
</div>
</div>
</div>
</div>