New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Как добавить поиск по связующим таблицам? #1581

Closed
mkomigor opened this Issue Dec 20, 2013 · 66 comments

Comments

Projects
None yet
7 participants
@mkomigor

Есть связка в моделе City

public function getCountry()
{
     return $this->hasOne(Country::className(), ['id' => 'country_id']);
}

И есть поиск сгенерированный крадом

public function search($params)
    {
        $query = City::find();
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $this->addCondition($query, 'id');
        $this->addCondition($query, 'country_id');
        $this->addCondition($query, 'name', true);
        $this->addCondition($query, 'create_time');
        $this->addCondition($query, 'update_time');
        return $dataProvider;
    }

Как добавить поиск по названию страны (атрибут $name в моделе Country)?

@cebe

This comment has been minimized.

Show comment
Hide comment
@cebe

cebe Dec 20, 2013

Member

You can add a join to the query:

$query->innerJoin('tbl_country c', 'country_id = c.id AND c.name LIKE :cname', [':cname' => '%'.$params['countryName'].'%']);

You need to add countryName to the $params before calling the method.

@qiangxue there was a question on IRC a few days ago that was about simplifying joins to relations.
Could be done by a method like joinRelation($relationName, $condition, $params) that would automatically call join internally by adding the table and link fields of the relation. What do you think?

Member

cebe commented Dec 20, 2013

You can add a join to the query:

$query->innerJoin('tbl_country c', 'country_id = c.id AND c.name LIKE :cname', [':cname' => '%'.$params['countryName'].'%']);

You need to add countryName to the $params before calling the method.

@qiangxue there was a question on IRC a few days ago that was about simplifying joins to relations.
Could be done by a method like joinRelation($relationName, $condition, $params) that would automatically call join internally by adding the table and link fields of the relation. What do you think?

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 20, 2013

Member

Will joinRelation() cause eager loading of the relation or is it only for filtering purpose?

Member

qiangxue commented Dec 20, 2013

Will joinRelation() cause eager loading of the relation or is it only for filtering purpose?

@cebe

This comment has been minimized.

Show comment
Hide comment
@cebe

cebe Dec 20, 2013

Member

Not sure, we might add a flag to add a with() call to, not sure about that.

$query->joinRelation('myrel', '...')->with('myrel')->all();
vs.
$query->joinRelation('myrel', '...', [], true)->all();

last param in joinRelation could toggle with but not sure if that is good.

Member

cebe commented Dec 20, 2013

Not sure, we might add a flag to add a with() call to, not sure about that.

$query->joinRelation('myrel', '...')->with('myrel')->all();
vs.
$query->joinRelation('myrel', '...', [], true)->all();

last param in joinRelation could toggle with but not sure if that is good.

@klimov-paul

This comment has been minimized.

Show comment
Hide comment
@klimov-paul

klimov-paul Dec 20, 2013

Member

@cebe, I have also thought about same thing.
We can create “joinRelation()” method, which can accept ActiveRelation object as an argument. This method should update the list of selected fields to include ones from related table. It also has to apply aliases for the involved tables. Joined relations should be eagerly populated.

Member

klimov-paul commented Dec 20, 2013

@cebe, I have also thought about same thing.
We can create “joinRelation()” method, which can accept ActiveRelation object as an argument. This method should update the list of selected fields to include ones from related table. It also has to apply aliases for the involved tables. Joined relations should be eagerly populated.

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 20, 2013

Member

This method should update the list of selected fields to include ones from related table.

Are you sure? This will require column name disambiguity.

Member

qiangxue commented Dec 20, 2013

This method should update the list of selected fields to include ones from related table.

Are you sure? This will require column name disambiguity.

@klimov-paul

This comment has been minimized.

Show comment
Hide comment
@klimov-paul

klimov-paul Dec 20, 2013

Member

Are you sure? This will require column name disambiguity.

I think it is necessary. Although the exact implementation and approach is still “to be defined”.

Member

klimov-paul commented Dec 20, 2013

Are you sure? This will require column name disambiguity.

I think it is necessary. Although the exact implementation and approach is still “to be defined”.

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 20, 2013

Member

I think we should avoid this. As you can see from Yii 1.1 implementation, disambiguity is not trivial at all. It also makes such query totally different from other queries in 2.0.

Member

qiangxue commented Dec 20, 2013

I think we should avoid this. As you can see from Yii 1.1 implementation, disambiguity is not trivial at all. It also makes such query totally different from other queries in 2.0.

@klimov-paul

This comment has been minimized.

Show comment
Hide comment
@klimov-paul

klimov-paul Dec 20, 2013

Member

Without disambiguity, it would be impossible to fetch main model with related one by single query in case they have at least one field with the same name for example “id”.

Member

klimov-paul commented Dec 20, 2013

Without disambiguity, it would be impossible to fetch main model with related one by single query in case they have at least one field with the same name for example “id”.

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 20, 2013

Member

If columns from two tables don't appear in select at the same time, we can disambiguate them through table name prefix, which is much easier.

Member

qiangxue commented Dec 20, 2013

If columns from two tables don't appear in select at the same time, we can disambiguate them through table name prefix, which is much easier.

@klimov-paul

This comment has been minimized.

Show comment
Hide comment
@klimov-paul

klimov-paul Dec 20, 2013

Member

Fine with me

Member

klimov-paul commented Dec 20, 2013

Fine with me

@cebe

This comment has been minimized.

Show comment
Hide comment
@cebe

cebe Dec 20, 2013

Member

I also think that this method should not try to do what we had in yii1.1 it should only be a shortcut that allows joining relations that are already defined. This way you avoid typing the fks again as they are already known by the relation.

Member

cebe commented Dec 20, 2013

I also think that this method should not try to do what we had in yii1.1 it should only be a shortcut that allows joining relations that are already defined. This way you avoid typing the fks again as they are already known by the relation.

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 20, 2013

Contributor

i also would like to see this in the guide with different other examples, can this be done?

Contributor

Ragazzo commented Dec 20, 2013

i also would like to see this in the guide with different other examples, can this be done?

@cebe

This comment has been minimized.

Show comment
Hide comment
@cebe

cebe Dec 20, 2013

Member

First it has to be implemented ;) docs will come of course.

Member

cebe commented Dec 20, 2013

First it has to be implemented ;) docs will come of course.

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 20, 2013

Contributor

sure) also is there any good example of this feature fo Yii1, i saw one but i dont like it because of messing model domain and some search. i think that for Yii1 it also should be in some guide, no?

Contributor

Ragazzo commented Dec 20, 2013

sure) also is there any good example of this feature fo Yii1, i saw one but i dont like it because of messing model domain and some search. i think that for Yii1 it also should be in some guide, no?

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 20, 2013

Member

I think we can let joinRelation() always cause eager loading of the corresponding related records.
I do need to introduce the join type parameter, which should default to inner join (because outer join doesn't help much for filtering purpose.)

Member

qiangxue commented Dec 20, 2013

I think we can let joinRelation() always cause eager loading of the corresponding related records.
I do need to introduce the join type parameter, which should default to inner join (because outer join doesn't help much for filtering purpose.)

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 20, 2013

Member

Perhaps name the method as joinWith().

Member

qiangxue commented Dec 20, 2013

Perhaps name the method as joinWith().

@cebe

This comment has been minimized.

Show comment
Hide comment
@cebe

cebe Dec 20, 2013

Member

Perhaps name the method as joinWith().

when it always includes eager loading joinWith() is a good name as it combines what already exists: join and with.

Member

cebe commented Dec 20, 2013

Perhaps name the method as joinWith().

when it always includes eager loading joinWith() is a good name as it combines what already exists: join and with.

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Dec 20, 2013

Member

I think join type may be useful. Inner join as default is fine though.

Member

samdark commented Dec 20, 2013

I think join type may be useful. Inner join as default is fine though.

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 21, 2013

Contributor

but join is slow, no?

Contributor

Ragazzo commented Dec 21, 2013

but join is slow, no?

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Dec 21, 2013

Member

Depends on the data.

Member

samdark commented Dec 21, 2013

Depends on the data.

@creocoder

This comment has been minimized.

Show comment
Hide comment
@creocoder

creocoder Dec 22, 2013

Contributor

Why not just add something like together relation option like in Yii 1.1.x?

Contributor

creocoder commented Dec 22, 2013

Why not just add something like together relation option like in Yii 1.1.x?

@klimov-paul

This comment has been minimized.

Show comment
Hide comment
@klimov-paul

klimov-paul Dec 22, 2013

Member

Why not just add something like together relation option like in Yii 1.1.x?

In this case ActiveQuery have to build join tree automatically. This is not a trivial task as we have found out during Yii 1.x development. That is why this feature has been dropped in Yii 2.

Introduction of some “joinWith()” method is a compromise. It allows you eager finding of the related models, while the composition of the query and “joins” are fully under developer control and responsibility.

Member

klimov-paul commented Dec 22, 2013

Why not just add something like together relation option like in Yii 1.1.x?

In this case ActiveQuery have to build join tree automatically. This is not a trivial task as we have found out during Yii 1.x development. That is why this feature has been dropped in Yii 2.

Introduction of some “joinWith()” method is a compromise. It allows you eager finding of the related models, while the composition of the query and “joins” are fully under developer control and responsibility.

@qiangxue qiangxue closed this in 4f44bb2 Dec 24, 2013

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 24, 2013

Contributor

@qiangxue will you add docs in the guide about how to use it in gridview?

Contributor

Ragazzo commented Dec 24, 2013

@qiangxue will you add docs in the guide about how to use it in gridview?

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 24, 2013

Member

Already added docs in the guide about how to use joinWith(). There is no suitable place to talk about gridview. This may be addressed in a wiki article or another guide that is mainly about commonly used widgets.

Member

qiangxue commented Dec 24, 2013

Already added docs in the guide about how to use joinWith(). There is no suitable place to talk about gridview. This may be addressed in a wiki article or another guide that is mainly about commonly used widgets.

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 24, 2013

Contributor

yes, guide about widgets would be more suitable, but there is no such guide, so i think it is needed to be created) joinWith returns only records from main table that has relations in other table, but this can be not right for some gridview widgets, i mean that relation record can be not set, and in gridview we will not get right data, how to handle this situation (i mean it should be LEFT JOIN, or when display data we will loose data from main table that dont have relation on other table)?

Contributor

Ragazzo commented Dec 24, 2013

yes, guide about widgets would be more suitable, but there is no such guide, so i think it is needed to be created) joinWith returns only records from main table that has relations in other table, but this can be not right for some gridview widgets, i mean that relation record can be not set, and in gridview we will not get right data, how to handle this situation (i mean it should be LEFT JOIN, or when display data we will loose data from main table that dont have relation on other table)?

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 24, 2013

Member

I don't quite get the problem you are describing here. Perhaps some examples? Just FYI, you can pass $eagerLoading and $joinType parameters to joinWith().

Member

qiangxue commented Dec 24, 2013

I don't quite get the problem you are describing here. Perhaps some examples? Just FYI, you can pass $eagerLoading and $joinType parameters to joinWith().

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 24, 2013

Contributor

example:

  • users
  • users_profiles

not every user have a profile (just an example), how correctly display this situation in gridview? yes i read docs about additional params, but if i do joinWith('profile') i will not get in dataprovider users that dont have profiles, right? how to solve this problem (with left join of course but how to do it in this case)? Can you give an example maybe for girdvew in this case? i will submit docs on widgets then with this example too.

Contributor

Ragazzo commented Dec 24, 2013

example:

  • users
  • users_profiles

not every user have a profile (just an example), how correctly display this situation in gridview? yes i read docs about additional params, but if i do joinWith('profile') i will not get in dataprovider users that dont have profiles, right? how to solve this problem (with left join of course but how to do it in this case)? Can you give an example maybe for girdvew in this case? i will submit docs on widgets then with this example too.

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 24, 2013

Member

Are you sorting by some columns in user_profiles? You should use LEFT JOIN in your case because you are not filtering users by users_profiles (something like User::find()->joinWith('users_profiles', true, 'LEFT JOIN')->all().

Member

qiangxue commented Dec 24, 2013

Are you sorting by some columns in user_profiles? You should use LEFT JOIN in your case because you are not filtering users by users_profiles (something like User::find()->joinWith('users_profiles', true, 'LEFT JOIN')->all().

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 25, 2013

Contributor

yes, display and sort for some columns in user_profiles too. So i need to make it like this:

public function search($params)
    {
        $query = Users::find();
        $query->joinWith('users_profiles', true, 'LEFT JOIN'); #this added
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $this->addCondition($query, 'id');
        $this->addCondition($query,'last_name',true); #this added
        $this->addCondition($query, 'name', true);
        $this->addCondition($query, 'create_time');
        $this->addCondition($query, 'update_time');
        return $dataProvider;
    }

am i right? will try this one one basic app.

Contributor

Ragazzo commented Dec 25, 2013

yes, display and sort for some columns in user_profiles too. So i need to make it like this:

public function search($params)
    {
        $query = Users::find();
        $query->joinWith('users_profiles', true, 'LEFT JOIN'); #this added
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $this->addCondition($query, 'id');
        $this->addCondition($query,'last_name',true); #this added
        $this->addCondition($query, 'name', true);
        $this->addCondition($query, 'create_time');
        $this->addCondition($query, 'update_time');
        return $dataProvider;
    }

am i right? will try this one one basic app.

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 25, 2013

Member

Yes, that's correct. You can just use $query->joinWith('users_profiles') because you are using exactly the default parameter values.

Member

qiangxue commented Dec 25, 2013

Yes, that's correct. You can just use $query->joinWith('users_profiles') because you are using exactly the default parameter values.

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 25, 2013

Contributor

aha, saw new refactoring. ok, will submit PR for widget gridvew then. Also should it be named widgets_gridview.md or in some other way?

Contributor

Ragazzo commented Dec 25, 2013

aha, saw new refactoring. ok, will submit PR for widget gridvew then. Also should it be named widgets_gridview.md or in some other way?

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 25, 2013

Member

Use widget-gridview.md so that it is consistent with other doc file naming. Thanks.

Member

qiangxue commented Dec 25, 2013

Use widget-gridview.md so that it is consistent with other doc file naming. Thanks.

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 25, 2013

Contributor

ok, looks like given approach not working, i added in User model (search model, not AR):

#added property
    public $last_name;

#search method
        $query = UserAR::find();
        $query->joinWith('profile');

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $this->addCondition($query, 'id');
        $this->addCondition($query, 'username', true);
        $this->addCondition($query, 'auth_key', true);
        $this->addCondition($query, 'password_hash', true);
        $this->addCondition($query, 'password_reset_token', true);
        $this->addCondition($query, 'email', true);
        $this->addCondition($query, 'role', true);
        $this->addCondition($query, 'status', true);
        $this->addCondition($query, 'create_time');
        $this->addCondition($query, 'update_time');
        $this->addCondition($query, 'last_name',true);
        return $dataProvider;

and in view:

    <?php echo GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'username',
            'auth_key',
            'password_hash',
            'password_reset_token',
            'last_name',
            // 'email:email',
            // 'role',
            // 'status',
            // 'create_time:datetime',
            // 'update_time:datetime',
            /*
            [
                'value' => function($data){
                    return is_null($data->profile) ? 'Not set' : $data->profile->last_name;
                }
            ],
             * 
             */
            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>

and i get

Unknown Propertyyii\base\UnknownPropertyException
Getting unknown property: app\models\User::last_name

why does it try to map db-fileds to an AR and not to a search model? O_O I did something wrong?

Contributor

Ragazzo commented Dec 25, 2013

ok, looks like given approach not working, i added in User model (search model, not AR):

#added property
    public $last_name;

#search method
        $query = UserAR::find();
        $query->joinWith('profile');

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $this->addCondition($query, 'id');
        $this->addCondition($query, 'username', true);
        $this->addCondition($query, 'auth_key', true);
        $this->addCondition($query, 'password_hash', true);
        $this->addCondition($query, 'password_reset_token', true);
        $this->addCondition($query, 'email', true);
        $this->addCondition($query, 'role', true);
        $this->addCondition($query, 'status', true);
        $this->addCondition($query, 'create_time');
        $this->addCondition($query, 'update_time');
        $this->addCondition($query, 'last_name',true);
        return $dataProvider;

and in view:

    <?php echo GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'username',
            'auth_key',
            'password_hash',
            'password_reset_token',
            'last_name',
            // 'email:email',
            // 'role',
            // 'status',
            // 'create_time:datetime',
            // 'update_time:datetime',
            /*
            [
                'value' => function($data){
                    return is_null($data->profile) ? 'Not set' : $data->profile->last_name;
                }
            ],
             * 
             */
            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>

and i get

Unknown Propertyyii\base\UnknownPropertyException
Getting unknown property: app\models\User::last_name

why does it try to map db-fileds to an AR and not to a search model? O_O I did something wrong?

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 25, 2013

Contributor

found temporary solution (hope it will not be official):

            [
                'value' => function($data){
                    return is_null($data->profile) ? 'Not set' : $data->profile->last_name;
                },
                'filter' => '<input type="text" class="form-control" name="User[last_name]" value=""/>',
            ],

but gridview does not use ajax, why? O_O and i always get in url something like this:

http://localhost:8000/index.php/users/index?User%5Bid%5D=&User%5Busername%5D=&User%5Bauth_key%5D=&User%5Bpassword_hash%5D=&User%5Blast_name%5D=asdasd

i even cant set client options for gridview to use ajax, because of this method implementation https://github.com/yiisoft/yii2/blob/master/framework/yii/grid/GridView.php#L206
Also how to make sorting on the related column? :)

Contributor

Ragazzo commented Dec 25, 2013

found temporary solution (hope it will not be official):

            [
                'value' => function($data){
                    return is_null($data->profile) ? 'Not set' : $data->profile->last_name;
                },
                'filter' => '<input type="text" class="form-control" name="User[last_name]" value=""/>',
            ],

but gridview does not use ajax, why? O_O and i always get in url something like this:

http://localhost:8000/index.php/users/index?User%5Bid%5D=&User%5Busername%5D=&User%5Bauth_key%5D=&User%5Bpassword_hash%5D=&User%5Blast_name%5D=asdasd

i even cant set client options for gridview to use ajax, because of this method implementation https://github.com/yiisoft/yii2/blob/master/framework/yii/grid/GridView.php#L206
Also how to make sorting on the related column? :)

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 25, 2013

Member

GridView doesn't support ajax natively in 2.0. We plan to introduce pjax to support ajax systematically.

Member

qiangxue commented Dec 25, 2013

GridView doesn't support ajax natively in 2.0. We plan to introduce pjax to support ajax systematically.

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 25, 2013

Contributor

We plan to introduce pjax to support ajax systematically.

hm, so currently gridview is not good enough?)) Also what about related column search? :) sorry if i am very annoying (

Contributor

Ragazzo commented Dec 25, 2013

We plan to introduce pjax to support ajax systematically.

hm, so currently gridview is not good enough?)) Also what about related column search? :) sorry if i am very annoying (

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 25, 2013

Member

GridView will be as is (perhaps with some minor enhancements). Column search also works, just not using ajax.

As I said, the main difference of GridView in 2.0 is that it doesn't support AJAX natively like in 1.1. Once we have the pjax widget, you will find ajax will work.

Member

qiangxue commented Dec 25, 2013

GridView will be as is (perhaps with some minor enhancements). Column search also works, just not using ajax.

As I said, the main difference of GridView in 2.0 is that it doesn't support AJAX natively like in 1.1. Once we have the pjax widget, you will find ajax will work.

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 25, 2013

Contributor

So no related column search? currently approach as i've described not working with joinWith?

Contributor

Ragazzo commented Dec 25, 2013

So no related column search? currently approach as i've described not working with joinWith?

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 25, 2013

Member

joinWith() should allow you to search related columns (you may want to use innerJoinWith() if you want to filter by related tables.)

Member

qiangxue commented Dec 25, 2013

joinWith() should allow you to search related columns (you may want to use innerJoinWith() if you want to filter by related tables.)

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 25, 2013

Contributor

hm, how correclty than use gridview in this situation? because it will not display search field for the additional column. And you also will get that exception as i described above.

Contributor

Ragazzo commented Dec 25, 2013

hm, how correclty than use gridview in this situation? because it will not display search field for the additional column. And you also will get that exception as i described above.

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 25, 2013

Member

Did you add a validation rule for last_name? Only active attributes can be searched for security purpose.

What's the complete error call stack?

Member

qiangxue commented Dec 25, 2013

Did you add a validation rule for last_name? Only active attributes can be searched for security purpose.

What's the complete error call stack?

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 25, 2013

Contributor

yes i added last_name in the safe of search model (model that holds search()). Complete error stack just have message that trying to access not existing property in AR because last_name is a property of related table, and ActiveDataProvider map fields on that AR. So currently there is no solution. the only solution that i see is to make search with SqlDataProvider, for example like this https://gist.github.com/Ragazzo/f31520ac9bf013477d43. But i thought that Yii2 widgets would be more useful and friendly, sad to note this(

Contributor

Ragazzo commented Dec 25, 2013

yes i added last_name in the safe of search model (model that holds search()). Complete error stack just have message that trying to access not existing property in AR because last_name is a property of related table, and ActiveDataProvider map fields on that AR. So currently there is no solution. the only solution that i see is to make search with SqlDataProvider, for example like this https://gist.github.com/Ragazzo/f31520ac9bf013477d43. But i thought that Yii2 widgets would be more useful and friendly, sad to note this(

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 25, 2013

Contributor

to avoid some misunderstandings i will post here full model and index view.

Contributor

Ragazzo commented Dec 25, 2013

to avoid some misunderstandings i will post here full model and index view.

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 25, 2013

Member

Since last_name belongs to the related model, you should configure the column and set value as an anonymous function to return the value of last_name from the related model.

Member

qiangxue commented Dec 25, 2013

Since last_name belongs to the related model, you should configure the column and set value as an anonymous function to return the value of last_name from the related model.

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 25, 2013

Contributor

SearchModel

<?php

namespace app\models\search;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\User as UserAR;

/**
 * User represents the model behind the search form about User.
 */
class User extends Model
{
    public $id;
    public $username;
    public $auth_key;
    public $password_hash;
    public $password_reset_token;
    public $email;
    public $role;
    public $status;
    public $create_time;
    public $update_time;
    public $last_name;

    public function rules()
    {
        return [
            [['id', 'create_time', 'update_time'], 'integer'],
            [['username', 'auth_key', 'password_hash', 'password_reset_token', 'email', 'role', 'status','last_name'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'username' => 'Username',
            'auth_key' => 'Auth Key',
            'password_hash' => 'Password Hash',
            'password_reset_token' => 'Password Reset Token',
            'email' => 'Email',
            'role' => 'Role',
            'status' => 'Status',
            'create_time' => 'Create Time',
            'update_time' => 'Update Time',
            'last_name' =>  'Last name'
        ];
    }

    public function search($params)
    {
        $query = UserAR::find();
        $query->joinWith('profile');

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $this->addCondition($query, 'id');
        $this->addCondition($query, 'username', true);
        $this->addCondition($query, 'auth_key', true);
        $this->addCondition($query, 'password_hash', true);
        $this->addCondition($query, 'password_reset_token', true);
        $this->addCondition($query, 'email', true);
        $this->addCondition($query, 'role', true);
        $this->addCondition($query, 'status', true);
        $this->addCondition($query, 'create_time');
        $this->addCondition($query, 'update_time');
        $this->addCondition($query, 'last_name',true);
        return $dataProvider;
    }

    protected function addCondition($query, $attribute, $partialMatch = false)
    {
        $value = $this->$attribute;
        if (trim($value) === '') {
            return;
        }
        if ($partialMatch) {
            $value = '%' . strtr($value, ['%'=>'\%', '_'=>'\_', '\\'=>'\\\\']) . '%';
            $query->andWhere(['like', $attribute, $value]);
        } else {
            $query->andWhere([$attribute => $value]);
        }
    }
}

index view

<?php

use yii\helpers\Html;
use yii\grid\GridView;

/**
 * @var yii\web\View $this
 * @var yii\data\ActiveDataProvider $dataProvider
 * @var app\models\search\User $searchModel
 */

$this->title = 'Users';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-index">

    <h1><?= Html::encode($this->title) ?></h1>

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('Create User', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?php echo GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'options' => [
            'ajaxUpdate' => true,
        ],
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'username',
            'auth_key',
            'password_hash',
            #'last_name', uncomment this and get exception
/*
Unknown Property – yii\base\UnknownPropertyException
Getting unknown property: app\models\User::last_name
*/
            // 'email:email',
            // 'role',
            // 'status',
            // 'create_time:datetime',
            // 'update_time:datetime',
            [
                'header' => 'Last name',
                'value' => function($data){
                    return is_null($data->profile) ? 'Not set' : $data->profile->last_name;
                },
                'filter' => '<input type="text" class="form-control" name="User[last_name]" value=""/>',
            ],
            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>

</div>
Contributor

Ragazzo commented Dec 25, 2013

SearchModel

<?php

namespace app\models\search;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\User as UserAR;

/**
 * User represents the model behind the search form about User.
 */
class User extends Model
{
    public $id;
    public $username;
    public $auth_key;
    public $password_hash;
    public $password_reset_token;
    public $email;
    public $role;
    public $status;
    public $create_time;
    public $update_time;
    public $last_name;

    public function rules()
    {
        return [
            [['id', 'create_time', 'update_time'], 'integer'],
            [['username', 'auth_key', 'password_hash', 'password_reset_token', 'email', 'role', 'status','last_name'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'username' => 'Username',
            'auth_key' => 'Auth Key',
            'password_hash' => 'Password Hash',
            'password_reset_token' => 'Password Reset Token',
            'email' => 'Email',
            'role' => 'Role',
            'status' => 'Status',
            'create_time' => 'Create Time',
            'update_time' => 'Update Time',
            'last_name' =>  'Last name'
        ];
    }

    public function search($params)
    {
        $query = UserAR::find();
        $query->joinWith('profile');

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $this->addCondition($query, 'id');
        $this->addCondition($query, 'username', true);
        $this->addCondition($query, 'auth_key', true);
        $this->addCondition($query, 'password_hash', true);
        $this->addCondition($query, 'password_reset_token', true);
        $this->addCondition($query, 'email', true);
        $this->addCondition($query, 'role', true);
        $this->addCondition($query, 'status', true);
        $this->addCondition($query, 'create_time');
        $this->addCondition($query, 'update_time');
        $this->addCondition($query, 'last_name',true);
        return $dataProvider;
    }

    protected function addCondition($query, $attribute, $partialMatch = false)
    {
        $value = $this->$attribute;
        if (trim($value) === '') {
            return;
        }
        if ($partialMatch) {
            $value = '%' . strtr($value, ['%'=>'\%', '_'=>'\_', '\\'=>'\\\\']) . '%';
            $query->andWhere(['like', $attribute, $value]);
        } else {
            $query->andWhere([$attribute => $value]);
        }
    }
}

index view

<?php

use yii\helpers\Html;
use yii\grid\GridView;

/**
 * @var yii\web\View $this
 * @var yii\data\ActiveDataProvider $dataProvider
 * @var app\models\search\User $searchModel
 */

$this->title = 'Users';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-index">

    <h1><?= Html::encode($this->title) ?></h1>

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('Create User', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?php echo GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'options' => [
            'ajaxUpdate' => true,
        ],
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'username',
            'auth_key',
            'password_hash',
            #'last_name', uncomment this and get exception
/*
Unknown Property – yii\base\UnknownPropertyException
Getting unknown property: app\models\User::last_name
*/
            // 'email:email',
            // 'role',
            // 'status',
            // 'create_time:datetime',
            // 'update_time:datetime',
            [
                'header' => 'Last name',
                'value' => function($data){
                    return is_null($data->profile) ? 'Not set' : $data->profile->last_name;
                },
                'filter' => '<input type="text" class="form-control" name="User[last_name]" value=""/>',
            ],
            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>

</div>
@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 25, 2013

Contributor

So how to get filter input for that new added filed from related table? in current implementation it is working but with bugs

  1. sorting not working (was trying ti setup it in different ways even through sort property of provider);
  2. search by related field working only once: if i add something in the filter it then sends get request, but rendered data will be with empty filter ofcourse as you can see. And the only ability to bring all data back i just to manually go to /users/index page.
Contributor

Ragazzo commented Dec 25, 2013

So how to get filter input for that new added filed from related table? in current implementation it is working but with bugs

  1. sorting not working (was trying ti setup it in different ways even through sort property of provider);
  2. search by related field working only once: if i add something in the filter it then sends get request, but rendered data will be with empty filter ofcourse as you can see. And the only ability to bring all data back i just to manually go to /users/index page.
@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 25, 2013

Contributor

@qiangxue i did it exactly, but search (filter search input) does not work because of problems that i described in above message )

Contributor

Ragazzo commented Dec 25, 2013

@qiangxue i did it exactly, but search (filter search input) does not work because of problems that i described in above message )

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 25, 2013

Member

I'm confused as you are describing several problems with different statuses. Anyway, I just tried relational query with GridView, and everything worked fine.

sorting not working (was trying ti setup it in different ways even through sort property of provider);

You need to configure the sort property to include last_name as validate sort attributes.

search by related field working only once:...

You don't need to configure the filter option (you also configured it incorrectly because you set value to be empty).

What other problems did you meet?

Member

qiangxue commented Dec 25, 2013

I'm confused as you are describing several problems with different statuses. Anyway, I just tried relational query with GridView, and everything worked fine.

sorting not working (was trying ti setup it in different ways even through sort property of provider);

You need to configure the sort property to include last_name as validate sort attributes.

search by related field working only once:...

You don't need to configure the filter option (you also configured it incorrectly because you set value to be empty).

What other problems did you meet?

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 25, 2013

Contributor

yes, i encountered a lot of problems :D some of them i solved some not)

  1. Sorting. Can you show how to set it correctly? I spend about 30 minutes with browsing in yii dataprovider code and was upset) because i dont know how to set it, i was trying (like in Yii1):
sort=> [
     'attributes' => ['last_name'],
],

but that is wrong and not working.

  1. Yes,right, i forgot to add to value data from $_GET. But anyway how to set it correctly? I thought that gridview can handle this by itself, no? If so, can you show how to do it :)

Have no other problems for now.

Contributor

Ragazzo commented Dec 25, 2013

yes, i encountered a lot of problems :D some of them i solved some not)

  1. Sorting. Can you show how to set it correctly? I spend about 30 minutes with browsing in yii dataprovider code and was upset) because i dont know how to set it, i was trying (like in Yii1):
sort=> [
     'attributes' => ['last_name'],
],

but that is wrong and not working.

  1. Yes,right, i forgot to add to value data from $_GET. But anyway how to set it correctly? I thought that gridview can handle this by itself, no? If so, can you show how to do it :)

Have no other problems for now.

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 25, 2013

Member
  1. In your search model, add the following lines:
$dataProvider->sort->attributes['last_name'] = [
    'asc' => ['profile.last_name' => SORT_ASC],
    'desc' => ['profile.last_name' => SORT_DESC],
];
  1. You don't need to set filter option at all. The grid column will add one by itself.
Member

qiangxue commented Dec 25, 2013

  1. In your search model, add the following lines:
$dataProvider->sort->attributes['last_name'] = [
    'asc' => ['profile.last_name' => SORT_ASC],
    'desc' => ['profile.last_name' => SORT_DESC],
];
  1. You don't need to set filter option at all. The grid column will add one by itself.
@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 25, 2013

Member

BTW, we are considering adding support for easier related field handling by GridView using dot syntax like in 1.1. There are already issues logged about this.

Member

qiangxue commented Dec 25, 2013

BTW, we are considering adding support for easier related field handling by GridView using dot syntax like in 1.1. There are already issues logged about this.

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 25, 2013

Contributor

BTW, we are considering adding support for easier related field handling by GridView using dot syntax like in 1.1. There are already issues logged about this.

what features are you talking about exactly? Also can we create one big issue with checkboxes-tasks for Gridview? it will be related to all issues mentioned for gridview features, but it will be easy to track them and see what we have and we will have :)

Contributor

Ragazzo commented Dec 25, 2013

BTW, we are considering adding support for easier related field handling by GridView using dot syntax like in 1.1. There are already issues logged about this.

what features are you talking about exactly? Also can we create one big issue with checkboxes-tasks for Gridview? it will be related to all issues mentioned for gridview features, but it will be easy to track them and see what we have and we will have :)

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 25, 2013

Member

It's about supporting dot syntax like profile.last_name, which will return the last_name value of the profile property.

What issues of gridview are you talking about specifically? So far, you were mainly talking about usage problems, not issues.

Member

qiangxue commented Dec 25, 2013

It's about supporting dot syntax like profile.last_name, which will return the last_name value of the profile property.

What issues of gridview are you talking about specifically? So far, you were mainly talking about usage problems, not issues.

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 25, 2013

Contributor

Still not working) http://gyazo.com/f028d899406cba6ce2fe54701d636b14.png

        $query = UserAR::find();
        $query->joinWith('profile');

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'sort' => [
                'attributes' => [
                    'asc' => ['profile.last_name' => SORT_ASC],
                    'desc' => ['profile.last_name' => SORT_DESC],
                ],
            ],
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $this->addCondition($query, 'id');
        $this->addCondition($query, 'username', true);
        $this->addCondition($query, 'auth_key', true);
        $this->addCondition($query, 'password_hash', true);
        $this->addCondition($query, 'password_reset_token', true);
        $this->addCondition($query, 'email', true);
        $this->addCondition($query, 'role', true);
        $this->addCondition($query, 'status', true);
        $this->addCondition($query, 'create_time');
        $this->addCondition($query, 'update_time');
        $this->addCondition($query, 'last_name',true);
        return $dataProvider;

in index view

    <?php echo GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'username',
            'auth_key',
            'password_hash',
            // 'email:email',
            // 'role',
            // 'status',
            // 'create_time:datetime',
            // 'update_time:datetime',
            [
                'header' => 'Last name',
                'value' => function($data){
                    return is_null($data->profile) ? 'Not set' : $data->profile->last_name;
                },
                #'filter' => '<input type="text" class="form-control" name="User[last_name]" value=""/>',
            ],
            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
Contributor

Ragazzo commented Dec 25, 2013

Still not working) http://gyazo.com/f028d899406cba6ce2fe54701d636b14.png

        $query = UserAR::find();
        $query->joinWith('profile');

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'sort' => [
                'attributes' => [
                    'asc' => ['profile.last_name' => SORT_ASC],
                    'desc' => ['profile.last_name' => SORT_DESC],
                ],
            ],
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $this->addCondition($query, 'id');
        $this->addCondition($query, 'username', true);
        $this->addCondition($query, 'auth_key', true);
        $this->addCondition($query, 'password_hash', true);
        $this->addCondition($query, 'password_reset_token', true);
        $this->addCondition($query, 'email', true);
        $this->addCondition($query, 'role', true);
        $this->addCondition($query, 'status', true);
        $this->addCondition($query, 'create_time');
        $this->addCondition($query, 'update_time');
        $this->addCondition($query, 'last_name',true);
        return $dataProvider;

in index view

    <?php echo GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'username',
            'auth_key',
            'password_hash',
            // 'email:email',
            // 'role',
            // 'status',
            // 'create_time:datetime',
            // 'update_time:datetime',
            [
                'header' => 'Last name',
                'value' => function($data){
                    return is_null($data->profile) ? 'Not set' : $data->profile->last_name;
                },
                #'filter' => '<input type="text" class="form-control" name="User[last_name]" value=""/>',
            ],
            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 25, 2013

Contributor

i guess i did something wrong because of even sorting now not working >_< god)

Contributor

Ragazzo commented Dec 25, 2013

i guess i did something wrong because of even sorting now not working >_< god)

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 25, 2013

Member

You should add my code after creating $dataProvider. Otherwise, you are overwriting the default attributes configuration.

Also, in your column specification about last_name, you need to add 'attribute' => 'last_name', because otherwise the column won't know how to bind the search model with the search field.

Member

qiangxue commented Dec 25, 2013

You should add my code after creating $dataProvider. Otherwise, you are overwriting the default attributes configuration.

Also, in your column specification about last_name, you need to add 'attribute' => 'last_name', because otherwise the column won't know how to bind the search model with the search field.

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 25, 2013

Contributor

right, search now working, but sort not) http://gyazo.com/9666db3bbf1fb83f935b0f25c6968039.png
i added as you said:

        $query = UserAR::find();
        $query->joinWith('profile');

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $dataProvider->sort->attributes['last_name'] = [
            'asc' => ['profile.last_name' => SORT_ASC],
            'desc' => ['profile.last_name' => SORT_DESC],
        ];


        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $this->addCondition($query, 'id');
        $this->addCondition($query, 'username', true);
        $this->addCondition($query, 'auth_key', true);
        $this->addCondition($query, 'password_hash', true);
        $this->addCondition($query, 'password_reset_token', true);
        $this->addCondition($query, 'email', true);
        $this->addCondition($query, 'role', true);
        $this->addCondition($query, 'status', true);
        $this->addCondition($query, 'create_time');
        $this->addCondition($query, 'update_time');
        $this->addCondition($query, 'last_name',true);
        return $dataProvider;

view

    <?php echo GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'username',
            'auth_key',
            'password_hash',
            // 'email:email',
            // 'role',
            // 'status',
            // 'create_time:datetime',
            // 'update_time:datetime',
            [
                'attribute' => 'last_name',
                'header' => 'Last name',
                'value' => function($data){
                    return is_null($data->profile) ? 'Not set' : $data->profile->last_name;
                },
                #'filter' => '<input type="text" class="form-control" name="User[last_name]" value=""/>',
            ],
            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
Contributor

Ragazzo commented Dec 25, 2013

right, search now working, but sort not) http://gyazo.com/9666db3bbf1fb83f935b0f25c6968039.png
i added as you said:

        $query = UserAR::find();
        $query->joinWith('profile');

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $dataProvider->sort->attributes['last_name'] = [
            'asc' => ['profile.last_name' => SORT_ASC],
            'desc' => ['profile.last_name' => SORT_DESC],
        ];


        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $this->addCondition($query, 'id');
        $this->addCondition($query, 'username', true);
        $this->addCondition($query, 'auth_key', true);
        $this->addCondition($query, 'password_hash', true);
        $this->addCondition($query, 'password_reset_token', true);
        $this->addCondition($query, 'email', true);
        $this->addCondition($query, 'role', true);
        $this->addCondition($query, 'status', true);
        $this->addCondition($query, 'create_time');
        $this->addCondition($query, 'update_time');
        $this->addCondition($query, 'last_name',true);
        return $dataProvider;

view

    <?php echo GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'username',
            'auth_key',
            'password_hash',
            // 'email:email',
            // 'role',
            // 'status',
            // 'create_time:datetime',
            // 'update_time:datetime',
            [
                'attribute' => 'last_name',
                'header' => 'Last name',
                'value' => function($data){
                    return is_null($data->profile) ? 'Not set' : $data->profile->last_name;
                },
                #'filter' => '<input type="text" class="form-control" name="User[last_name]" value=""/>',
            ],
            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 25, 2013

Contributor

You should add my code after creating $dataProvider. Otherwise, you are overwriting the default attributes configuration.

strange behavior, in Yii1 when i specify it, it works well, maybe it should be like in Yii1?

Contributor

Ragazzo commented Dec 25, 2013

You should add my code after creating $dataProvider. Otherwise, you are overwriting the default attributes configuration.

strange behavior, in Yii1 when i specify it, it works well, maybe it should be like in Yii1?

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 25, 2013

Contributor

What issues of gridview are you talking about specifically? So far, you were mainly talking about usage problems, not issues.

true, i almost forgot them while trying to make this one work)) but i remember also that big issue with long discussion about gridview features, so i though that issue-task is a good solution to once again summarize developers needs/suggestions.

Contributor

Ragazzo commented Dec 25, 2013

What issues of gridview are you talking about specifically? So far, you were mainly talking about usage problems, not issues.

true, i almost forgot them while trying to make this one work)) but i remember also that big issue with long discussion about gridview features, so i though that issue-task is a good solution to once again summarize developers needs/suggestions.

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 26, 2013

Member

Remove header (otherwise it would overwrite the sort link).

Member

qiangxue commented Dec 26, 2013

Remove header (otherwise it would overwrite the sort link).

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 26, 2013

Contributor

Ok,now working. Always was misunderstanding header/label options of column.

@qiangxue many thanks for your detailed explanations, will submit PR on widget usage, also maybe will add SqlDataProvider usage with gridview. Sorry for being such a newbie :)

Contributor

Ragazzo commented Dec 26, 2013

Ok,now working. Always was misunderstanding header/label options of column.

@qiangxue many thanks for your detailed explanations, will submit PR on widget usage, also maybe will add SqlDataProvider usage with gridview. Sorry for being such a newbie :)

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Dec 26, 2013

Member

Reopening this one for documentation purposes.

Member

samdark commented Dec 26, 2013

Reopening this one for documentation purposes.

@samdark samdark reopened this Dec 26, 2013

@cebe

This comment has been minimized.

Show comment
Hide comment
@cebe

cebe Dec 26, 2013

Member

Isn't this enough documentation? https://github.com/yiisoft/yii2/blob/master/docs/guide/active-record.md#joining-with-relations

Or do you want to add the gridview questions to the docs?

Member

cebe commented Dec 26, 2013

Isn't this enough documentation? https://github.com/yiisoft/yii2/blob/master/docs/guide/active-record.md#joining-with-relations

Or do you want to add the gridview questions to the docs?

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 26, 2013

Contributor

@cebe yes, i will make a PR with widgets-gridview.md for ActiveDataProvider/SqlDataProvider for using with gridview.

Contributor

Ragazzo commented Dec 26, 2013

@cebe yes, i will make a PR with widgets-gridview.md for ActiveDataProvider/SqlDataProvider for using with gridview.

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Dec 27, 2013

Member

It's gridview part that is tricky.

Member

samdark commented Dec 27, 2013

It's gridview part that is tricky.

@samdark samdark removed this from the 2.0 Beta milestone Mar 7, 2014

qiansen1386 pushed a commit to qiansen1386/yii2 that referenced this issue Mar 9, 2014

@cebe cebe added this to the 2.0 Beta milestone Apr 11, 2014

@cebe cebe self-assigned this Apr 11, 2014

@cebe

This comment has been minimized.

Show comment
Hide comment
@cebe

cebe Apr 11, 2014

Member

working on this.

Member

cebe commented Apr 11, 2014

working on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment