AccessRules by Expression

Can someone provide an example of using exp​ression in accessRules ?

Thanks

In a rule, you can set its 'exp​ression' as follows,

'exp​ression'=>PHP exp​ression

If the exp​ression evaluates true, this rule applies.

Hi qiang

I tried using this:

'exp​ression'=>$user->role->name=='editor'

where role is mapped to user with relation

but it throws error that 2nd argument must be array

when it is changed to array($user->role->name=='editor')

…it doesn't throw error but it doesn't work still.

please provide an example if possible.

There's a bug which has been fixed in SVN.

The exp​ression must be given as a string (not a value). For example:



<?php


'exp​ression'=>'!$user->isGuest && $user->role->name=="editor"'