StrongSquirrel / yii2-crud

CRUD extension for Yii2
MIT License
7 stars 1 forks source link

Search action #4

Closed frostealth closed 9 years ago

frostealth commented 9 years ago

Added strongsquirrel\actions\SearchAction.

Usage: Controller SiteController.php

public function actions()
{
    return [
        'search' => [
            'class' => SearchAction::className(),
            'modelClass' => MySearchModel::className(),
            'httpMethod' => SearchAction::HTTP_METHOD_GET,
        ],
    ];
}

Model MySearchModel.php

class MySearchModel extends Model
{
    // ...

    public function search()
    {
        $query = MyModel::find();
        if ($this->validate()) {
            $query->filterWhere($this->getAttributes());
        }

        return new ActiveDataProvider(['query' => $query]);
    }
}

View search.php

echo GridView::widget([
    'dataProvider' => $dataProvider, // instance of [[ActiveDataProvider]]
    'filterModel' => $filterModel, // instance of [[MySearchModel]]
    // ...
]);
chuprik commented 9 years ago

Could you add author phpdoc in each classes?

frostealth commented 9 years ago

Only classes or methods too?

chuprik commented 9 years ago

Only classes or methods too?

all classes, I want see you as author.

frostealth commented 9 years ago

Done

frostealth commented 9 years ago

All right?

chuprik commented 9 years ago

yeah. thank you!