Skip to content
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

GridView can not load class with twig #3971

Closed
cansozeri opened this issue Jun 19, 2014 · 17 comments
Closed

GridView can not load class with twig #3971

cansozeri opened this issue Jun 19, 2014 · 17 comments
Assignees
Labels
Milestone

Comments

@cansozeri
Copy link

Hi My code is

{{ GridView.widget({
            'dataProvider': dataProvider,
            'filterModel': searchModel,
            'columns': [
                'username', 'email:email','last_visit_time',
                {'class': 'yii\grid\ActionColumn'},
            ],
 }) | raw}}

I have added GridView as global in my config file like this

'GridView' => '\yii\grid\GridView'

But I get this error and I can not use ActionColumn class ...

An exception has been thrown during the rendering of a template ("Class yiigridActionColumn does not exist") in "index.htm" at line 15.

Caused by: ReflectionException
Class yiigridActionColumn does not exist

in C:\EasyPHP\data\localweb\test\vendor\yiisoft\yii2\di\Container.php at line 408

So what's the problem over here ???

Regards,

@samdark samdark self-assigned this Jun 19, 2014
@samdark samdark added this to the 2.0 RC milestone Jun 19, 2014
@samdark
Copy link
Member

samdark commented Jun 19, 2014

The issue will be fixed when I'll merge #3535

@cansozeri
Copy link
Author

untill that time I can not use as I understand : )) I hope you gonna merge very soon : ))

Do you know how can I use it with twig ??

[
      'attribute' => 'status',
      'value' => function ($model) {
          return $model->getStatus();
    }
],

@samdark
Copy link
Member

samdark commented Jun 19, 2014

I'm working on the merge right now.

@samdark
Copy link
Member

samdark commented Jun 19, 2014

As I know, you can't use anonymous functions with twig at all.

@cansozeri
Copy link
Author

So how can I get status of the users with GridView ?? Like this

<?php echo GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            //['class' => 'yii\grid\SerialColumn'],
            //'id',
            'username',
            'email:email',
            //'password_hash',
            //'password_reset_token',
            // 'auth_key',
            [
                'attribute' => 'status',
                'value' => function ($model) {
                        return $model->getStatus();
                    }
            ],
            'last_visit_time',
            // 'create_time',
            // 'update_time',
            // 'delete_time',

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>

@samdark
Copy link
Member

samdark commented Jun 19, 2014

Either configure it elsewhere or just use status w/o anonymous function. Twig automatically tries to call getters.

@cansozeri
Copy link
Author

Thanx, I'll try : ))

@cansozeri
Copy link
Author

It works like this thanx again : ))


{{ GridView.widget({
            'dataProvider': dataProvider,
            'filterModel': searchModel,
            'columns': [
                'username', 
                'email:email',

                  {
                    'attribute' : 'status',
                    'value' : this.getStatus()
                  },

                'last_visit_time',

            ],
        }) | raw}}

@samdark
Copy link
Member

samdark commented Jun 20, 2014

Should be like this when #3978 will be merged:

{{ grid_view_widget({
            'dataProvider': dataProvider,
            'filterModel': searchModel,
            'columns': [
                'username', 
                'email:email',
                  {
                    'attribute' : 'status',
                    'value' : this.getStatus()
                  },
                'last_visit_time',
            ],
        })
}}

@cansozeri
Copy link
Author

So what about this, I can not use layouts from another folder in my twig files with extends. Can you add this functionality too ..

#3907

@cansozeri
Copy link
Author

Still can not load class am I have to change anything else ??

{{ grid_view_widget({
            'dataProvider': dataProvider,
            'filterModel': searchModel,
            'columns': [
                'username', 'email:email','last_visit_time',
                {'class': 'yii\grid\ActionColumn'},
            ],
 }) | raw}}

An exception has been thrown during the rendering of a template ("Class yiigridActionColumn does not exist")

@grachov
Copy link
Contributor

grachov commented Jun 20, 2014

You should use 'yii\\grid\\ActionColumn' instead of 'yii\grid\ActionColumn'.

@samdark
Copy link
Member

samdark commented Jun 20, 2014

@grachov it was able to load both ways for me.

@cansozeri
Copy link
Author

@grachov it works thanx ..

@grachov
Copy link
Contributor

grachov commented Jun 20, 2014

@samdark I'm not sure how it can be working, but as I know Twig uses stripcslashes for strings so \ is removed. That's why in that merged code was added support for / in namespaces.

@samdark
Copy link
Member

samdark commented Jun 20, 2014

Ah, I was talking about / :)

@cansozeri
Copy link
Author

Hi How can I define this form in our new twig way ??

      $form->field($model, 'status')->dropDownList([
        User::STATUS_INACTIVE => $model->getStatus(User::STATUS_INACTIVE),
        User::STATUS_ACTIVE => $model->getStatus(User::STATUS_ACTIVE),
        User::STATUS_SUSPENDED => $model->getStatus(User::STATUS_SUSPENDED),
        User::STATUS_DELETED => $model->getStatus(User::STATUS_DELETED),
    ])

in twig I dont know how can use "User::STATUS_SUSPENDED " like static calls ....

and in my model there is a function getStatus .. So I want to call it too but with model.getStatus is firing an error too I think..

A hash key must be followed by a colon (:). Unexpected token "punctuation" of value "." ("punctuation" expected with value ":")

{{ use('auth\models\User') }}

{{ form.field(model, 'status').dropDownList({

            User::STATUS_INACTIVE : model.getStatus(User::STATUS_INACTIVE),
        User::STATUS_ACTIVE : model.getStatus(User::STATUS_ACTIVE),
        User::STATUS_SUSPENDED : model.getStatus(User::STATUS_SUSPENDED),
        User::STATUS_DELETED : model.getStatus(User::STATUS_DELETED),

 }) | raw}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants