Statically calling another controller method in a layout

Here’s what I have inside my main layout. Its used for the main navigation:

                        $this->widget('application.components.MainMenu', array(

                            'activeCssClass' => 'navOn',

                            'items' => array(

                                array('label' => 'Home', 'url' => array('/site/index'), 'active' => isItemActive($this->route, 'site'), 'items' => SiteController::getSubNav()),

                                array('label' => 'Inbox', 'url' => array('/inbox/index'), 'active' => isItemActive($this->route, 'inbox'), 'items' => InboxController::getSubNav()),

                                array('label' => 'Payables', 'url' => array('/payables/index'), 'active' => isItemActive($this->route, 'payables')),

                                array('label' => 'Receivables', 'url' => array('/receivables/index'), 'active' => isItemActive($this->route, 'receivables')),

                                array('label' => 'Documents', 'url' => array('/documents/index'), 'active' => isItemActive($this->route, 'documents')),

                                array('label' => 'Reports', 'url' => array('/reports/index'), 'active' => isItemActive($this->route, 'reports')),



The problem is if I’m inside the Inbox controller, the SiteController:: call gets an error saying:

include(SiteController.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory 

The quick fix for this would be to manually include every controller needed in this layout but hoping there’s a more Yii way to do it.

Or another fix would be to have a static array for the main navigation. I’d like to avoid this so that as I add controllers, they can just handle their own navigation stuff.

Inside your main config import controllers you need:






But maybe it’s just not the best idea to store menu items inside different controllers. You can create your own Menu widget and store all menu & submenu items there. But looks like it’s a matter of taste.

I think you should also start looking into actions. They, along with widgets, will handle all of your modularity issues.