We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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, cars_locations, cars_types

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 ? ..



43.9k
Accepted
answer


85.5k

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
));


23.6k

Thanks on help both...

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