Render menu on view

Generated crud from gii

standard views from yii

Database:

projects can have many risks, issues, incidents, etc… all tables have a projectId fk.

What i want to do:

When a user selects (views) a specific project, i set (setState) projectId.

Then i display a menu to navigate to risks, issues, incidents, specific to the project: where project_id = yii::app()->user->projectId

I can display the menu through layout. Create layout and call menu.

Question, how can i display a menu (component) only when view. and not when create and such?

It is not very clear what you are asking but if you want to display the Yii menu in a particular view file just call




$this->menu=array(

	array('label'=>'View', 'url'=>array('view')),

	array('label'=>'Update', 'url'=>array('update')),

);



else please give an example of what exactly is that you need

Thanks for the reply.

What i want to do is display the menu in all view files except a select few. How can this be accomplished?

then remove the above code from that view

In your view, where you render the menu (f.e. layouts/main.php), you can check the current action of the controller.





if($this->action->id != 'create') 

{   

   ...

   //render your menu  

   ...

}

  



If you have different controllers you can check the current controllers id (AdminController …) too





$doRenderMenu = $this->id == 'admin' && $this->action->id != 'view'

               // && .... add more conditions here


if($doRenderMenu) 

{   

   ...

   //render your menu  

   ...

}

  



Hi ,

I am new in yii. I want to put all the menu item’s logic or role based menu logic, such as [Create user menu will only be available to admin not to user ] . so I want to put all my menu related logic in a a page and I want to call the page from a cmenu widget every time. Is this possible?

Just like roles are checked to confirm that user is authorized to do a particular work or not?