Include a menu on every page? use url helper in a class? |
[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.
[eluser]DogWin[/eluser]
我用jquery的click事件在同一页表达的. menu Code: <a href="#" id="one">one</a>
[eluser]daparky[/eluser]
This should help you: http://codeigniter.com/wiki/Header_and_f...very_page/
[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
[eluser]haloace[/eluser]
Thanks all for your input. Learning new techniques is always good. I ended up going for a simple approach. Code: //controller
[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.
[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?
[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
[eluser]InsiteFX[/eluser]
Looks like you need to setup the CSS file and the navigation divisions in code. Enjoy InsiteFX
[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. |
Welcome Guest, Not a member yet? Register Sign In |