[Yii Smart Menu] Extension

[b]Yii Smart Menu

[/b]

Auto check permissions to define visibility of any menu item. Works out of the box with Rights Extension. Can be adapted to work in (almost) any enviroment.

YiiSmartMenu iterates through the items received to turn visibility=true|false depending on checkAccess results. The authItemName to be checked is formed by concatenating Module (whether any), Controller and Action defined in ‘url’ or ‘submit’ (inside linkOptions) options of your menu’s items.

More in the Extension’s Page

[color="#006400"]/* moved to extensions forum */[/color]

Sorry, and thanks for moving.

Improved documentation.

Code examples are now available.

  • Version 0.2.1[list]
  • Allow to set the new option ‘params’=>array(…) in a menu item to be sent to checkAccess() function instead of the default var $_GET;
  • Allow to set the new option ‘authItemName’=>‘CanDoX’ in a menu item to be used in checkAccess() function instead of auto generate it based in ‘url’ or ‘submit’ options;

[/list]

Look nice…but didn’t try yet…

Good work… :rolleyes:

Thank you Zainiafzan. Hope it to be useful to u.

New GitHub repository:

https://github.com/sidtj/Yii-Smart-Menu

  • Version 0.3.0[list]
  • Looks for url/submit additional params to send to checkAccess() if ‘authParams’ is not setted. $_GET will only be sent if ‘authParams’ is not setted and url/submit has no additional params;
  • Improoved trace messages. Now they show what params are being sent to checkAccess();
  • The code has been refactored;

[/list]

Sid,

Is there a chance to use it with an installation of PHP 5.1?

Do I have to remove the ucfirst() function ?

Regards

Hi Kavitama,

Yes, it should work fine if you just remove/replace the function.

I dont remember any other PHP 5.3 restriction for now.

Regards.

Sidney,

Boa tarde,

Parabéns pela extensão. Porém, tentei utilizá-la aqui e não consegui. Já tenho o Rights funcionando perfeitamente então, teoricamente, se eu efetuar o login com o perfil de admin (super usuario), o menu deveria mostrar todos os ítens nos quais eu tenho acesso, correto? Desculpe a minha ignorância, mas tentei bastante aqui e não consegui. Quando uso a extensão, mesmo logado como admin, tambem não consigo acessar o rights diretamente pela url "index.php?r=righs".

Muito obrigado!,

Oi Fábio, obrigado.

Acredito que seu problema ao acessar o Rights não tenha relação com a extensão pois ela apenas afeta os menus que a utilizam. Quanto ao menu oculto, você precisa lembrar que se você definir ‘url’=>’#’ sem um ‘submit’=>‘xxxx’, este menu ficará oculto (e todos os submenus) pois provavelmente não há um authItemName chamado {Controller}.# em suas permissions.

O que você pode fazer é definir você mesmo o nome do auth item usando a opção authItemName ou então definir você mesmo a visibilidade do menu com o visible=>{regra} e deixar que o YSM cuide dos submenus.

Outra coisa muito útil é ativar os trace logs do yii (mais informações) pois o YiiSmartMenu mostra mensagens que explicam porque cada item foi exibido ou ocultado.

Ver os exemplos na página da documentação talvez possa ser de ajuda também.

Obrigado.

Hey guys.

I love this extension, but I have switched from using Rights to using UserGroups and I was wondering if anyone could point me in the right direction to modify this extension in order that it might be used outside of Rights?

I am still a yii noob, but I am learning fast and loving it.

Thanks

I just looked at UserGroups and it looks great. I am just starting an app, and I installed yii-user and rights, and I think I want to use UserGroups instead. I would love an answer to this same question: How to use this with UserGroups.

I am very busy these days but I will try to take that in account in the next release.

For now, I can not imagine a way to check access through accessRules (i am not familiar with filter for now) but I guess it should not be so hard to implement. As soon as I can I will try to publish at least a workaround.

Any insights about how to check permissions using filters are very welcome, anyway.

Thank you.

Hi all, I implemented this extension and its working great for the most part. The only issue I am have is when I do any searches in my Admin menus I get an error. I have posted a pic to demo what issue I am having. Any help?

Thanks

Hi PabloPunch,

Did you solved your problem? I am also getting the same issue. If you have solved this please kindly share that to this forum

While going through solving the problem I stuck to this line

147 protected function compoundParams($item) {

148 if (isset($item[‘authParams’]))

149 return $item[‘authParams’];

150 else

151 {

152 /* If item has an url option and it has additional params */

153 if (isset($item[‘url’]) && is_array($item[‘url’]) && count($item[‘url’]) > 1)

154 return array_slice($item[‘url’], 1, null, true);

155 /* Else if item has an submit option and it has addtionall params */

156 elseif (isset($item[‘linkOptions’][‘submit’]) && is_array($item[‘linkOptions’][‘submit’]) &&count($item[‘linkOptions’][‘submit’]) > 1)

157 return array_slice($item[‘linkOptions’][‘submit’], 1, null, true);

158 else

159 return $_GET;

160 }

161 }

Can you please help me what should we need to return in case returning the params as $_GET order to get the result bug free while searching

While going through the solutions i came to know that we need to define the

the menu as yiismartmenu compatible setting ‘authParams’=>‘to some values’

inside ‘url’ as

‘url’=>array(/site/index’, ‘authParams’=>‘to some values’)

In order to ignore the returned result from $_GET