JavaScript week JavaScript week
This week up to 80% off on HTML/CSS and JavaScript courses.

Discussion: PHP MVC CMS -- Adding Dynamic Navigation Functionality

Activities (2)
Michael MacDonald:7. May 3:59

The course was extremely well written, am very greatful.

I have a question about the MVC pattern, with this course I was able to add a lot of different functionality myself(I've gone ahead and added a realestate type plugin to that cms, and have extended the administration panel to include functionality for it. However something that has me stumped is adding a dynamic navigation component. Where the navigation menu is populated from a database, I'm unsure of where to place it in the scheme of things(as I want that to be included on every page like the layout.phtml is. It should then display differently according to access(admins get another nav menu as well as the basic one, where as normal people just get the basic one).

Database side of things: I've created a navigation table, I've also created a nav-user table(to help combat the many to many relationship).
Model side of things: I've created a NavigationManager (This successfully pulls information from the database and stores it(Tested it).
View side of things: I've created a foreach loop function that would work if I didn't have inheritance problems, I know that the NavigationManager isn't connecting to the view directly(which is good, because it's not suppose to, but unfortunately the array can't populate with my current inheritance problems. The way I've got the Navigation view connected is via a "include_once" statement on the main "layout.php" which I am unsure whether this is correct way of doing it or not.
Controller side of things: Unsure of what the NavigationCon­trolller is meant to do, so I've kind of left that, and just added the one function I need in the controller (To getNavUrl).

Obviously this is wrong, I am just unsure of where I went wrong, and how to correct :( Please help me!! :(

Reply 7. May 3:59
David Capka team
Replies to Michael MacDonald
David Capka:7. May 6:43

Hi Michael, we're glad you like the course :) As you said, the menu will be visible on every subpage of your website. It's a similar thing to the flash messages mechanism. I'd put it to the RouterController (the process() method), instantiate your NavigationManager there and pass data from it to the view as $this->data['...'].... Code rendering the menu items would then be part of the layout.phtml template.

You would create a navigation controller if you wanted it to be displayed on a particular subpage only. You put the shared logic as messages, navigation, layout and this stuff directly to the RouterController.

If you needed any more help, just ask :)

Up Reply 7. May 6:43
You can walk through a storm and feel the wind but you know you are not the wind.
Michael MacDonald:7. May 7:29

Hello David,

So in the layout, I would place the same kind of php tags as you would for displaying the messages.

Place the controller logic in the RouterController(as in that calls the NavigationManager functions I want to use EG getNavUrls and passes the information into the view via the same data tags that were used for messages.

Thank you for your help.
I'll let you know how I go.

Up Reply  +1 7. May 7:29
To maintain the quality of discussion, we only allow registered members to comment. Sign in. If you're new, Sign up, it's free.

3 messages from 3 displayed.