views:

28

answers:

1

I have created a generic "Page" controller for my site. These pages serve up mostly static information, they pull the most recent version of the page contents, and the update date from a database. On each page they have a section menu and a resource menu. The section menu is dictated by what logical section of the site the page resides in. The resource menu holds links to resources associated with that page, documents, offsite-links, links to calender events, etc. These resources are page specific and also pulled from a database.

Currently the Page controller generates them and places them in the view, but I am staring work on other controllers that may have only one, both, or none of the menus. Should I continue having the menu selection and generation be a function of the Page controller and copy paste it to new controllers? Or should I somehow break out the menu lookup and generation functions into some other object (library, helper, or plugin)? And if so how should I break it out? Or how else should I implement it?

A: 

You can do several things but the important thing to remember is to try and have the code once, so for the menu you dont want to copy and paste it.

If you are defining a menu based on user permission's or something you can check these things in the view for example:

<?php if ($this->tank_auth->checkPerm('Backup')) : ?>
    <div class="menu_item" id="menu4">...
<?php endif; ?>

You can also send parameters to the view from the controller if you want to change the menu depending on the page or a variety of things.

There should be no need to make a library, helper or plugin.

Kieran Andrews