Hello! Can you give me an example of serach form processing. Can I do it with ORM? For example I need to process the next form: <form> <select name="from_year"> <select name="to_year"> <input name="from_price"> <input name="to_price"> <button> </form>
And one more question. How can I set "where", if, for examlpe, user did'nt set "from_price".
<?php echo Form::select('body_type', 'none', Model_Advert::bodyoption(), array('class' => 'span2', 'multiple'));?> This expression gives only last element. What do you mean "input form field must be an array"?
On the basis of this form processing I try to make something like API.
So, I useController_Rest
class Controller_Getlist extends Controller_Rest { public function post_search() { $query = Model_Advert::query(); $input = Input::post('brand_id', false) and $query->where('brand_id', '=', $input);
... (another filtration)
return $query->get(); } }
Now I want to add "array" of original_path's to images belongs to every advert_id (reverce relations belongs to and has many are already described in models -as you already understend, each advert has many images).
This is properties array in model Images: protected static $_properties = array ( 'image_id', 'advert_id', 'original_path', );
So, I have no idea how to add in "return" array of original_paths to every advert. I think that it is simple if you know how to do it :) But I don't know.
The return value of a REST method must be either an array, or null (nothing) in case you've used $this->response() to set the response value(s).
You can not return ORM objects, the REST base controller doesn't know how to convert that to an array (which is required to create a json object that is usable).
So you need to convert the query result to an array that you can return.
OK, I've changed "return" to "$this->response()" but I can not understand how to add "images" to response.
So, for example, if now answer is something like "array ('4' => array ('title' => 'MyTitle', 'brand_id'=>'7'))"
How can I make the result like "array ('4' => array ('title' => 'MyTitle', 'brand_id'=>'7', 'images' => array ('25' =>'qwerty.jpg','26'=>'wertyu.jpg')))"
where 25 and 26 - image_id and qwerty.jpg and wertyu.jpg - original_path for the advert_id = 4.