[Extension] Menubuilder

Discuss the extension menubuilder here.

Hi, i have this error try access index.php/menubuilder with the basic configuration "usort(): Array was modified by the user comparison function" in menubuilder/components/EMBFileAdapter.php

Any idea?

See the comment at the extensions documentation.

menubuilder is now available on github too.

You also can report issues there.

Screenshot?? demo page???

screenshot is at the extensions documentation, no demo available

hello, how can i simulate a menu to show different menuitem for different access

this is my issue:

i have 3 access.. isGuest(not  logged in) , isAdmin(loggedin as admin) and  authenticated(logged in as normal user ,eg demo). i want  to create one menu that will display different menuitem  for different  access. pls help

You can find a similiar topic in the online documentation - see Advanced/Customizing

  1. You have to create a ‘Datafilter’ component that extends EMBDataFilter. Place it in your menubuilder module/components.

You have to override the methods

  • getSupportedUserRoles()

  • getCurrentUserRoles()




class AdminRoleDataFilter extends EMBDataFilter

        {

            public static function getSupportedUserRoles() //returns guest, authenticated, admin roles

            {

                return array_merge(parent::getSupportedUserRoles(),array('admin'=>'Admin'));

            }


            public static function getCurrentUserRoles() //returns guest or authenticated, admin ... roles

            {

                if(Yii::app()->user->id == 'admin') //check your admin-role here

                      return array('authenticated'=>'Authenticated user','admin'=>'Admin');

                else

                      return parent::getCurrentUserRoles(); //authenticated or guest       

            }

       }             

             



Install the AdminRoleDataFilter instead of the default in config/main.php





'modules'=>array(

 

        'menubuilder'=>array(

            ...

            'dataFilterClass'=>'AdminRoleDataFilter',

 

        ),

)




thanks so much, i did that but implementing it in the menu is the issue,

FROM THE DUMMY MENU INSTALLED , LETS SAY

yiiframework menu item should be seen by admin only

resources should be seen by authenticated users only

contact should be seen by guest only

while home should be seen by all,

how can implement that…

i would love to hear from you!

If you have installed the 3 roles, you will find this roles in the menu- and menuitem form.

You can add one or more roles to a whole menu or single menuitems.

If you don’t add roles, the menu/item will be visible for all users, otherwise for the users with the assigned roles only.

So you should be able to build your menu as wish.

But I would split it into two menus - ‘main’ and ‘admin’ with a ‘Admin’ label as root (no url assigned, add all admin-subitems, assign the admin role in the menu, not to every admin-item) and merge these menus in the layout view, like described in the documentation.

hello i did is you said, but when i create a menu called ‘admin’ with only ‘admin’ userrole selected, i get an error,

this is the error

Error 500

Trying to get property of non-object

should i select authenticated and admin as my userrole?

Maybe a bug?

It’s hard to reproduce without more information: error 500, which line, which object …?

  • Where is the error: In menubuilder admin-form or on rendering the menu?

  • Can you debug the project?

Maybe you can upload your modified menubuilder module code (not the core) and the zip-file of your exported menu here.

Hi All

i install this module and Browse to the menubuilder module (yourapp/index.php/menubuilder). some interface

display. but didn’t installed the menus from data/installmenus.php and data/installmenuitems.php On the first run.

my questions are :

1- how to install menue in data/installmenus.php and data/installmenuitems.php ? or how to create new menu?

2- this module works file to store menue items or db?

following file that attached is screen shot pic that i see.

It seems, that the files data/installmenu-items are not found.

The demo-data should be installed at the first usage.

Did you follow the install-instructions correctly?

The default value of dataFilePath=‘menubuilder.data’ (=moduleId.data),

but you can assign this property of the module in the config/main.php - as alias path.

What happens if you execute ‘Utilities’->reinstall?

It seems to be a bug, that if you are not able to create a menu manually, if the default menus could not be created from data/installmenus.

I will investigate this issue.

Hi

1-Tanks for your reply. I followed install-instructions step by step.

2-yes The default value of dataFilePath=‘menubuilder.data’ is :




class EMBMenubuilderModule extends CWebModule

{

...

    protected $_dataFilePath='menubuilder.data'; //allow set






3- when i try ‘Utilities’->reinstall i get this error

"No menu found: Please create a menu" .Attached file show this.

I going to create new app and then install menubuilder module . I try to report you any result. :)

  • is the module property $checkInstall=true ?

  • In EMBAdminController::actionIndex there are the lines




  if ($module->checkInstall)

        {

            $this->install();

        }




Are you able to debug the code here, why the installfiles are not found?

Hi,

First of all thanks for the nice and powerfull extension. I love it, but I have a small question.

Can anyone please explain why I have to define the userRoles explicitly to force the menu to show?

Here is my implementation





$userRoles = array('Guest');


if(!empty(Yii::app()->user->id)):

	$userRoles = array();

	$roles=Rights::getAssignedRoles(Yii::app()->user->Id);

	foreach($roles as $authItem)

		$userRoles[] = $authItem->name;

endif;


/* Menubuilder begins */

$items=$this->createWidget('ext.menubuilder.widgets.EMBMenu', array(

	//'menuIds'=>'main',

	'scenarios'=>array('frontend'),

	'userRoles'=>$userRoles,

	'menuBuilderItemsBefore' => false,

	'menuOptions'=> array(

			'items'=>array(

				array('url'=>array('/menubuilder'),'label'=>'Menubuilder'),

			)

		),

	)

)->getItems();

 

$this->widget('bootstrap.widgets.TbNavbar', array(

	'collapse' => true,

	'items' => array(

		array(

			'class' => 'bootstrap.widgets.TbMenu',

			'encodeLabel'=>false,

			'items' => $items,

		)

	)

));




Here is my config




/* Menubuilder */

		'menubuilder'=>array(

            'theme'=>'bootstrap', //comment for bluegrid theme (=default)

            'checkInstall'=>false, //uncomment after first usage

            'cacheDuration'=> -1, //uncomment for disabling the menucaching

            'languages'=>array('en_us','da'),

            'supportedScenarios'=>array('backend' => 'Backend', 'frontend' => 'Frontend', 'dashboard' => 'Dashboard'),

			'dataFilterClass'=>'Datafilter',

            //set EMBDbAdapter to switch to mysql (checkInstall=>true on first run)

            //'dataAdapterClass'=> 'EMBDbAdapter', //'EMBMongoDbAdapter',


            //the available menus/lists for the preview

            'previewMenus'=>array(

               // 'superfish'=>'Superfish',

               // 'mbmenu'=>'MbMenu',

                'bootstrapnavbar'=>'Bootstrap Navbar',

                'bootstrapmenu'=>'Bootstrap Menu',

              // 'dropdownlist'=>'Dropdownlist',

                'unorderedlist'=>'Unordered list'

            )

        ),



Have a nice day friends :)

Babak

You don’t have (and should not) assign the userroles when rendering the menu.

This property is for simulate mode only.

But the menubuilder should know the roles of the current user (and all supported roles, for displaying in the dropdown of the menubuilder admin).

So you have to install your own datafilter component, as described here:

http://www.yiiframework.com/extension/menubuilder/#hh9

The YourDataFilter::getCurrentUserRoles should contain your lines from above


 

$userRoles = array();

$roles=Rights::getAssignedRoles(Yii::app()->user->Id);

        foreach($roles as $authItem)

                $userRoles[] = $authItem->name;

return $userRoles;



YourDataFilter::getSupportedUserRoles should return all available roles (to assign to a menu/item).

Place your component in your modules working copy in the components folder and register it in config/main.php as your datafilter.

But you have to install the current version of the EMBDataFilter from Github before, because of a bug (using static::getCurrentUserRoles() instead of self::getCurrentUserRoles() in the method checkRoles.

Hi Joblo,

I was run data/installmenus.php and data/installmenuitems.php

but not working anymore, can you post demo like multimodelform??

:rolleyes:

thanks

Yes there is an issue with installing.

The next release of menubuilder will come soon.

Ok, maybe with demo.