PHP code example of mazpaijo / yii2-querybuilder

1. Go to this page and download the library: Download mazpaijo/yii2-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/ */

    

mazpaijo / yii2-querybuilder example snippets



use leandrogehlen\querybuilder\QueryBuilderForm;

 QueryBuilderForm::begin([
    'rules' => $rules,
    'builder' => [
        'id' => 'query-builder',
        'filters' => [
            ['id' => 'id', 'label' => 'Id', 'type' => 'integer'],
            ['id' => 'name', 'label' => 'Name', 'type' => 'string'],
            ['id' => 'lastName', 'label' => 'Last Name', 'type' => 'string']
        ]
    ]
 ])


use leandrogehlen\querybuilder\Translator;

public function actionIndex()
{
      $query = Customer::find();
      $rules = Json::decode(Yii::$app->request->get('rules'));
      if ($rules) {
          $translator = new Translator($rules);
          $query
            ->andWhere($translator->where())
            ->addParams($translator->params());
      }
      
      $dataProvider = new ActiveDataProvider([
          'query' => $query,
      ]);
    
      return $this->render('index', [
          'dataProvider' => $dataProvider,
          'rules' => $rules
      ]);
}

php composer.phar