![]() |
Database-driven menu -- what's the best approach? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Database-driven menu -- what's the best approach? (/showthread.php?tid=50250) |
Database-driven menu -- what's the best approach? - El Forum - 03-20-2012 [eluser]MatBeard[/eluser] I'm new to CI, but thus far I think it's brilliant... flexible enough to get things done without having to follow conventions. Now to my 'problem'... I need to generate a menu structure from a database. I've got no issue with the database schema or required queries, I just don't know the best approach to getting the content onto each page. Note, I used the words 'each page' rather than 'each view' -- I realise I can create the appropriate model and load the data into all views from all controllers, but this seems rather repetitive. The reason I'm doing this (in case it helps with an alternative solution) is I'll be using a role-based permission system of some sort and I only want to display menus appropriate to the logged in user. Any suggestions are much appreciated. Database-driven menu -- what's the best approach? - El Forum - 03-22-2012 [eluser]cbwd[/eluser] Not 100% sure I understood what you're asking, but wouldn't you just create a helper that builds your menus for you? If I'm on the wrong track, please be a bit more specific with the question. Cheers Database-driven menu -- what's the best approach? - El Forum - 03-22-2012 [eluser]CroNiX[/eluser] I created a simple library that assembles the login status, header, menu, footer, etc. All I do is pass it the page title and content created from my current controller to the template library and it does the rest. In my controller I do my stuff and... Code: //used to hold the data that will go to the content view Then in template::make_page(), something like: Code: public function make_page($title = '', $content = '') Then you can have different methods for pages with sidebars, admin, etc. Hope that helps. Database-driven menu -- what's the best approach? - El Forum - 03-23-2012 [eluser]MatBeard[/eluser] Hi CroNiX, That looks just like the kind of thing I'm after. Thanks. I did manage to work something out, but it involved pulling data directly from a model in the view... I didn't really want to start a project with bad habits. I should be able to adapt your suggestion to meet my needs. Just out of interest, what's the Auth code you're using. Is it 'home-grown' or one of the available helper classes? Thanks again. Mat |