Include a menu on every page? use url helper in a class? - 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: Include a menu on every page? use url helper in a class? (/showthread.php?tid=24033) Pages:
1
2
|
Include a menu on every page? use url helper in a class? - El Forum - 10-28-2009 [eluser]haloace[/eluser] I'm new to CI and the MVC style. What's the best way to include a menu on every page? Can I use a ci helper in a class? Basically, I tried to create a class with my menu (using the url helper) and load it in the controller on each page, but it's not working. //controller function function index() { $this->load->library('Menu'); $menu = new Menu(); $this->load->view('header',$menu); $this->load->view('home'); $this->load->view('footer',$menu); } //class class Menu { $this->load->helper('url'); $this->$url['home'] = anchor(base_url(), 'home', array('title' => 'home')); $this->$url['about'] = anchor('about/', 'about', array('title' => 'about')); $this->$url['forum'] = anchor('forum/', 'forum', array('title' => 'forum')); $this->$url['faq'] = anchor('faq/', 'faq', array('title' => 'faq')); } Thanks for any help. Include a menu on every page? use url helper in a class? - El Forum - 10-29-2009 [eluser]DogWin[/eluser] 我用jquery的click事件在同一页表达的. menu Code: <a href="#" id="one">one</a> Include a menu on every page? use url helper in a class? - El Forum - 10-29-2009 [eluser]daparky[/eluser] This should help you: http://codeigniter.com/wiki/Header_and_footer_and_menu_on_every_page/ Include a menu on every page? use url helper in a class? - El Forum - 10-29-2009 [eluser]John_Betong[/eluser] I have just written a common menu for our latest project. It checks the URL against the menu item title and if there is a match then the class changes to highlight the particular page item title. Code: // CSS file edit: spelling and formatting Include a menu on every page? use url helper in a class? - El Forum - 10-29-2009 [eluser]haloace[/eluser] Thanks all for your input. Learning new techniques is always good. I ended up going for a simple approach. Code: //controller Include a menu on every page? use url helper in a class? - El Forum - 10-30-2009 [eluser]jedd[/eluser] [quote author="haloace" date="1256893585"] Learning new techniques is always good. Code: include("menu.inc"); I'd suggest this is actually a very old technique. And I'd strongly recommend you don't do this. At the very least turn it into a helper. If you want to learn a new technique, and actually take advantage of CodeIgniter's features, use Colin's templating system, or the view-preparation in MY_Controller approach. Include a menu on every page? use url helper in a class? - El Forum - 10-30-2009 [eluser]haloace[/eluser] [quote author="jedd" date="1256921226"][quote author="haloace" date="1256893585"] Code: include("menu.inc"); I'd suggest this is actually a very old technique. And I'd strongly recommend you don't do this. At the very least turn it into a helper. [/quote] What is the disadvantage of this technique? Include a menu on every page? use url helper in a class? - El Forum - 10-30-2009 [eluser]NateL[/eluser] [quote author="John_Betong" date="1256844243"] I have just written a common menu for our latest project. It checks the URL against the menu item title and if there is a match then the class changes to highlight the particular page item title. Code: // CSS file edit: spelling and formatting[/quote] I was JUST trying to figure this part of my site out. Very helpful code for me! Thanks a bunch! For some reason tho, every instance that gets echoed out in the foreach statement is in the "off" state. Any ideas why? Code: $a = array Include a menu on every page? use url helper in a class? - El Forum - 10-30-2009 [eluser]InsiteFX[/eluser] Looks like you need to setup the CSS file and the navigation divisions in code. Enjoy InsiteFX Include a menu on every page? use url helper in a class? - El Forum - 10-30-2009 [eluser]NateL[/eluser] [quote author="InsiteFX" date="1256984997"]Looks like you need to setup the CSS file and the navigation divisions in code. Enjoy InsiteFX[/quote] My CSS is set up and working properly. I tested this by swapping the "class='active'" to the "off" position and they all lit up as "active" if I put in this line of code: echo $this->uri->uri_string; it echos "about" - so I'm expecting to see my About page with the active list item, but it doesn't work for me. |