PHP code example of tonisormisson / yii1-querybuilder

1. Go to this page and download the library: Download tonisormisson/yii1-querybuilder library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tonisormisson / yii1-querybuilder example snippets


echo CHtml::beginForm();
$this->widget('ext.yii1-querybuilder.QueryBuilder',
    [
        'model'=>$model,
        'attribute'=>'myquerystring',
        'filters'=>[
            ['id'=>'name','label'=>'Name (string)','type'=>'string'],
            ['id'=>'age','label'=>'Age (integer)','type'=>'integer'],
            ['id'=>'height','label'=>'Height (double)','type'=>'double'],
            ['id'=>'birthday','label'=>'Birthday (date)','type'=>'date'],
            ['id'=>'time','label'=>'Time (time)','type'=>'time'],
            ['id'=>'changed_at','label'=>'Last changed (datetime)','type'=>'datetime'],
            ['id'=>'is_active','label'=>'Is Active? (boolean)','type'=>'boolean'],
        ],
        'rules'=>$rules,

    ]);

echo CHtml::submitButton('go');
echo CHtml::endForm();


public function actionIndex()
{
    $model = new SomeModel();
        if(isset($_POST['SomeModel'])){
            $model->attributes =$_POST['SomeModel'];
            $rules = json_decode($someModel->myquerystring);
            if($rules){
                Yii::import('application.extensions.yii1-querybuilder.Translator');
                // translate rules to SQL (with params)
                $translator = new Translator($rules);
                // feed the translated sql & params to Yii find() method
                $result = SomeModel::model()->find($translator->where, $translator->params);
            }
        }
        $this->render('index',[
            'rules'=>$rules,
        ]);
}