query inside model with dynamic condition

hi all developer i have query like this ini zend framework 1

function atDaftarJoinPeran($peran_id,$modul_id=null,$parent=null,$enable=null,$app_id=null) {
    $s = $this->select();
            (cr_hak_akses.MODUL_ID=cr_menu.MODUL_ID or cr_hak_akses.MODUL_ID=\'all\') and
            (cr_hak_akses.KONTROLER_ID=cr_menu.KONTROLER_ID or cr_hak_akses.KONTROLER_ID=\'all\') and
            (cr_hak_akses.AKSI_ID=cr_menu.AKSI_ID or cr_hak_akses.AKSI_ID=\'all\')
    if ($parent) {
        $s->where('PARENT_MENU_ID = ?',$parent);
    } else {
        $s->where('PARENT_MENU_ID IS NULL');
    if ($modul_id) {
    if ($enable) {
    if ($app_id) {

    $rs = $this->fetchAll($s);
    return $rs;

how can i convert that query into phalcon and place it in model not in controller.

in zend i can make query with multi condition simply by inject $s->where clause or $s->join before query execution (fetch).

thanks before

See http://docs.phalconphp.com/en/latest/reference/phql.html#creating-queries-using-the-query-builder


$s = $this->getModelsManager()->createBuilder();

And use $s->andWhere()


thanks for the answer,

i mean how can i split into multiple statement, not in 1 statement

this is single statement and work ```php $user = $this->modelsManager->createBuilder() ->from('Sistem\Model\CrUser') ->where('user_aktif = :x:', array('x' => 1)) ->getQuery() ->execute(); foreach ($user as $x) { echo $x->user."<br>"; } ```

this is multi statement and doesnt work ```php //this is not working $user = $this->modelsManager->createBuilder()->from('Sistem\Model\CrUser'); $user->where('user_aktif = :x:', array('x' => 1)); $user->getQuery()->execute(); foreach ($user as $x) { echo $x->user."<br>"; } ```

how can i make multi statement query builder work?

thanks before


ok i make it work ```php $builder = $this->modelsManager->createBuilder(); $builder->where('useraktif = :x:', array('x' => 1)); $builder->orWhere('peranid = :y:',array('y'=>'opr')); $builder->from('Sistem\Model\CrUser');

    $user = $builder->getQuery()->execute();
    foreach ($user as $x) {
        echo $x->user."<br>";

``` before "from" must splitted