Welcome Guest, Not a member yet? Register   Sign In
Library or helper?

I am having trouble managing my left sidebar navigation for my product catalog. The navigation is two levels deep and appears across all pages. I am currently loading a "leftnav_view" on all pages but to get this to function it requires many database queries to get what department the user is in as well as what category and product. Doesn't seem like elegant, reusable code.

Should I make a Library or a Helper Class to manage this better? Any tips on how others have handled a basic navigation?

It kinda depends: do you use multiple controllers, or only one?

I'd make my constructor look like this:
function __construct()
    // do all your queries here
    // use a model to interact with your database if necessary
    $array['navi'] = ''; //get the array that's needed for the navigation
and then you can use $navi in your leftnav_view

[eluser]Rick Jolly[/eluser]
Being a fan of modularity, I'd use a helper or library and call it from the view. That way, you can include the menu in any view without syncing with the controller. Ideally, you'd cache the menu to avoid all the queries on every request. You'd have to use a third party cache library for that.

[eluser]RaZoR LeGaCy[/eluser]
Use zend_cache for that purpose, it rocks.

Theme © iAndrew 2016 - Forum software by © MyBB