How to access methos/property from another Controller

How do I access a getter in one controller from another controller (and/or the main layout)?

In AboutController:

 public function getSubMenu() {

   return array(

      array('label'=>'Contact Us','url'=>array('page', 'view'=>contact')),

      . . .



In layouts/main.php



      array('label'=>About Us','url'=>array('/about/index'),'items'=><img src='' class='bbc_emoticon' alt='???' />?->SubMenu()),


What goes in

<img src='' class='bbc_emoticon' alt='???' />?

Thanks all.

Why dont you create a helper object or a widget submenu or … there are tones of solutions better than accessing a controller. Stick with MVC pattern my friend, it is a recommendation and let controllers to do what they best do :)

Cheers man

I guess I’m trying to understand the MVC and haven’t gotten it all right yet :)

I was thinking of using getSubMenu() so that I could use it in MainMenu as well as a sidebar.

One way is to define them as static function. However helper function is better if you will be re-using in lot many controllers.

Then I recommend you to create a widget. Here is an example (and one extension widget ) to look at or implement in your project :

I am trying to place the code for the subMenu items in one place then use it in a couple. I have set up a website that the default page lists these options in the $content area. I would also like to have them available in a dropdown of the main menu. So I thought that placing them in the controller was the best place.

When you say create a “helper” what do you mean/how? I am really new to MVC and don’t understand some of it’s concepts…Where to put what, etc…


Here is a wiki that may help you, is for a sidebar but the concept is the same.

Also take a look to the best practices.

If you want to place someware some code that you will use in more than one place, don’t place in controller, controller are meant to be as thin as possible.

Create a component for this: the easiest way is to add a file SubMenu.php in component and implement a static function.

If you want to do something more complex, with some possibility of configuration, follow the link of Antonio and create a widget.