My Symfony submenu

September 16, 2008

Ok, I needed a submenu that needed to be different between some different modules. Being a symfony newb Ads pointed me towards the component_slot. Perfect!

Ok so first I created a submenu module and the component class. In the component class I define the elements of the submenu links (they’ll do as hardcoded atm).  Instead of having to create a partial for each menu type, I created a single partial and placed that in the global templates folder, _submenu.php:

<ul>
<?php foreach ($opts AS $label => $url):?>
<li><?php echo link_to($label,$url)?></li>
<?php endforeach?>
</ul>

The comonent class where I define the submenu options/links:

class submenuComponents extends sfComponents
{
// default backend submenu
public function executeDefault()
{
$opts = array(‘Login’ => ‘@sf_guard_signin’
);
echo get_partial(‘../submenu’,array(‘opts’ => $opts));
return true;
}

// blog admin section submenu
public function executeBlog()
{
$opts = array(
‘Posts’ => ‘@postList’,
‘Comments’ => ‘@commentList’,
‘Categories’ => ‘@categoryList’,
);
echo get_partial(‘../submenu’,array(‘opts’ => $opts));
return true;
}

// user admin section submenu
public function executeUser()
{
$opts = array(
‘Users’ => ‘sfGuardUser/index’,
‘User Permissions’ => ‘sfGuardPermission/index’,
‘User Groups’ => ‘sfGuardGroup/index’
);
echo get_partial(‘../submenu’,array(‘opts’ => $opts));
return true;
}
}

Now all I have to do is configure each module to use a module type. The menu will default to the one set in the app/global view.yml

global view.yml:

default:
components:
submenu: [submenu, default]

Example module view.yml (ie: blogPost) selecting a different submenu:

default:
components:
submenu: [submenu, blog]

For the sfGuard modules I created a module folder to my app for all the modules I wanted to select a submenu for. Then added a view.yml and selected a menu like the call above.

It all seems to be working well :D~. THanks adam ❤

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: