Форма из шапки стандартного шаблона:<form action="/search" method="post" name="search" id="search_form">
<input type="text" name="s" id="search_input"/>
<input type="submit" name="bsearch" value="Поиск">
</form>
Контроллер:class SearchController extends AppController
{
public function indexAction()
{
if (isset($_POST['bsearch'])){
$search_model = new Search();
$search_data = $_POST['s'];
$result = $search_model->search($search_data);
}
$this->set(compact('data', 'result'));
}
}
Модель: class Search extends Model
{
public function search($word){
$word = htmlspecialchars($word);
if($word === ''){ return false; };
$query = '';
$array_words = explode(' ',$word);
foreach ($array_words as $key => $value){
if (isset($array_words[$key-1])){
$query .= ' OR ';
}
$query .= 'title LIKE "%'. $value .'%"';
}
$query_reruslt = $this->selectData($query);
return $this->sortData($query_reruslt);
}
public function selectData($query){
return $this->db->query("SELECT * FROM products WHERE {$query}");
}
public function sortData($query_reruslt){
$data = [];
foreach ($query_reruslt as $item){
$data[$item['id']] = $item;
}
return $data;
}
}
Во вьюшке так чисто для теста:<?php foreach ($debug as $item):?>
<?php echo $item['title']?>
<?php endforeach; ?>