FormGrid Kartik

Guys,

I’m using the formgrid http://demos.krajee.com/builder-details/form-grid developed by Kartik but I have some fields that I want to be visible only for administrators.

I’m trying to do like I do in the menu by adding:

‘visible’=>Yii::$app->user->can(‘administrator’),

but it didn’t work. Any idea?

it should work, the problem could be in other place.

I usually just run debugger and see what happens. Do you know how to setup debugger? What IDE do you use?

I have the debug toolbar but not sure what do I need to look for.

The visibility works on the Menu::widget but not on Kartik components.

I ment you need to run Xdebug. If you do not know what is it and how to use it, check google. You also will need some IDE, l prefer PHPStorm.

Lex,

I use Dreamweaver. I can’t afford PHPStorm now.

So are you saying that the code should works?

Use Netbeans, it’s free.

I’m not sure of there’s an option for visibility there. You can always prepare the attributes array first, different for different roles, and then use it inside FormGrid.

You should use proper IDE and learn how to use Xdebug to dig in the framework code. Without those tools you can not create something more advanced as a blog. Keep in mind that Yii have best comments in a framework core among all other frameworks, and the code is rather simple if we compare with Symfony and Laravel. So you should use the code of the framework as a main documentation.

Bizley,

how can I do that? What I’m doing that is checking on my model the role but than it still show an empty input text if it’s not the admin. I want to completely remove the text input when it’s not admin.

I’m guessing you do have something like:




'rows' => [

    [

        'attributes' => [

            // ...

        ]

    ],

    [

        'attributes' => [

            // ...

    ],

],



so use variable there:




'rows' => $rows,



that is prepared first roles-wise:




if (Yii::$app->user->can('administrator')) {

    $rows = [

        [

            'attributes' => [

                // all the rows and attributes for administrators

            ]

        ],

    ];

} else {

    $rows = [

        [

            'attributes' => [

                // all the rows and attributes for non-administrators

            ]

        ],

    ];

}



This is just a general idea.

Thanks Bizley.

I ended up just creating different forms for different roles.

Thanks Bizley.

I ended up just creating different forms for different roles.