Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Phalcon search preform

Hello,

I need a advice with my search section ... Il give an example of what I need.

Il recive a GET request from my front - end (AngularJS) and it will look like this:

/cars/search/{condition}/{type}/{location}/{year}

DB name : cars DB tables : cars, carslocations, carstypes

I have to handle request, preform search and output all cars with that conditions with my api in JSON and send back to my front - end ..

What is the best way to preform this search ? ..



29.9k
Accepted
answer


60.9k

How i do it This is the short version more or less, I hope it will help you out

function getBuilder(){

    $builder = new \Phalcon\Mvc\Model\Query\Builder();
    $builder->from('MyApp\Models\Cars');

    if ($_POST['year_from'] > 0 ){
        $builder->andWhere('year > "year_from', [ 'year_from' => $_POST['year_from']; 
    }

    //and so on and so on..... where i build my whole query

}


$builder = getBuilder();

$paginator = new \Phalcon\Paginator\Adapter\QueryBuilder(array(
    "builder" => $builder,
    "limit"=> 40,
    "page" => $pageNum
));


8.6k

Thanks on help both...

I used named routes to handle url request and preform search based on my url parameters ...