Git Product home page Git Product logo

yii1-querybuilder's Introduction

Yii1 QueryBuilder widget

This is an implementation of jQuery Querybuilder for Yii1

DEMO

https://demo.andmemasin.eu/yii1-querybuilder/

Dependencies

this widget depends on jQuery and Bootstrap3. Due to Yii1 widgets logic the widget itself does not manage the dependencies. You need to install & load the jQuery and Bootstrap3 in your app yourself prior using this widget!

Basic usage example

In view:

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

In Controller:

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,
        ]);
}

yii1-querybuilder's People

Contributors

tonisormisson avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.