We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Customising Scaffold code

$this->view->title = 'Search Customer ::';
        $numberPage = 1;
        if ($this->request->isPost()) 
            $query = Criteria::fromInput($this->di, "Customer", $_POST);
            $this->persistent->parameters = $query->getParams();
            $numberPage = $this->request->getQuery("page", "int");

        $parameters = $this->persistent->parameters;
        $parameters["order"] = "cus_id";

        if (!is_array($parameters)) 
            $parameters = array();


        $customer = Customer::find($parameters);

This is a slightly modified scaffold code to search. I want to add one more condition to the query. The above code will return result for the query

  • select from customer where name like '%foo%' I wanto to change the query into something like

  • select from customer where name like '%foo%' and user_name = 'user_name'

user_name can be get from session data


Not possible to customise ?


I tried the code from the link. As the last post says, I am also getting 'At least one model is required to build the query' error


Ah I see; I didn't test this before. Seems to me this functionality is not quite working as it should.

This works for me but seems to miss the point of using the Criteria object in the first place;


        $criteria = Criteria::fromInput($this->di, 'Customer', $this->request->getPost());

        $params = $criteria->getParams();

        $result = $this->modelsManager
            ->where($criteria->getConditions(), $params['bind'])
            ->addWhere('user_name = "user_name"')


Thanks, now it's working. How to add more conditions. Just for knowing. Also there is a typo

addWhere('user_name = "user_name"')

Which is wrong

andWhere('user_name = "user_name"')

is the correct.