You need to implement a filter for the goods (for example, with / without photos, with / without description, etc.). If the parameter is not specified, then nothing needs to be added to the request.

public function action_index() { $orm = ''; if(isset($_POST['filter_submit'])) { if(!empty($_POST['filter_name'])) { $name = $_POST['filter_name']; $orm .= "->where('name', '=', $name)"; } switch($_POST['filter_main_image']) { case 1: $orm .= "->where('main_image','!=','')"; break; case 2: $orm .= "->where('main_image','=','')"; break; } // Как здесь прикрутить переменную $orm перед find_all() $products = ORM::factory('product')->find_all(); } $content = View::factory('admin/a_products/va_products_index') ->bind('products', $products); // Выводим в шаблон $this->template->page_title = 'Продукты'; $this->template->block_center = array($content); } 

I am ready to listen to any other options how this can be implemented, because this option is not a cake.

    2 answers 2

     ORM::factory('product') 

    Returns an object, pass it to a variable first, then, if necessary, set the where clause, then find_all ().

    something like this:

     $orm = ORM::factory('product'); switch ($value) { case '1': $orm->where('1','=','1'); break; } $products = $orm->find_all(); 
    • and if there is a lot of switch, won't he catch only the last one? - Demyan112rv 6:01 pm
    • Yes, as many as you like - Nord001
    • try your solution - Demyan112rv
    • PySy. I advise you to read the code and documentation :) class Kohana_ORM extends Model implements serializable // Alias ​​of and_where () public function where ($ column, $ op, $ value) We wrote about Arr class, good advice, read: kohanaframework.org/3.2/ guide / api / Arr - Nord001 6:08 pm
    • Your solution works) Thank you. Kohanu is learning the second month. I don’t know much yet) - Demyan112rv
     switch($_POST['filter_main_image']) { case 1: $orm .= "->where('main_image','!=','')"; break; case 2: $orm .= "->where('main_image','=','')"; break; default: $orm .= ""; // типа ничего не выбрано break; } 

    and take requests through the class Arr in Kohana itself

    • Can you give me a little more detail, like via Arr - Demyan112rv 5:59 pm