![]() |
Creating a Navigation Site with a Database in CI - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Creating a Navigation Site with a Database in CI (/showthread.php?tid=19447) |
Creating a Navigation Site with a Database in CI - El Forum - 06-08-2009 [eluser]crispinatari[/eluser] Hi everyone!! :-) While i'm enjoying using codeignitor so far i've been having trouble understanding the relationships between the numbers of controllers i need to create for each page in my website. Is it one controller to maintain all of the pages required in index or would there be controllers made for each seperate page eg.(site_controller, mainpage_controller, schools_controller, courses_controller, students_controller, results_controller) with seperate index functions for each page. I've created a database in SQL but now i'm creating a site to view the pages. I'm creating a site_page that will feature a left_menu, a header a footer with a home(main) page in the center that navigates to those four different table views(pages)within the main page but i don't want the header, footer, or left menu to dissapear from view, the table (page) views are school, course, student and result, and i've called them studentlistview etc ... My struggle has been creating a navigational website using the controller, i'm not 100% sure how to lay it out properly as i'm quite new to the MVC concept and i haven't found one tutorial that really covers this specific area in great detail. So how do you make every page feature the header, footer, left_menu while making ONLY the main content navigate from page to page. its certainly a brain masher ![]() So the student controller page is something like this: student_controller.php Code: <?php studentlistview.php Code: <html> studentaddview.php Code: <html> DO I NEED SOMETHING LIKE THIS? Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); Creating a Navigation Site with a Database in CI - El Forum - 06-08-2009 [eluser]TheFuzzy0ne[/eluser] Generally, a controller should represent a "module" of your site. In this case it's "students". Generally, you'd have methods such as add, delete, show and update. You can include views from within views by simply calling $this->load->view('header') or something along those lines. Creating a Navigation Site with a Database in CI - El Forum - 06-08-2009 [eluser]crispinatari[/eluser] I still dont have a clear understanding of how it all fits together as a whole navigational website and the correct coding, i've tried for days now... its all a bit too much, i give up =( Creating a Navigation Site with a Database in CI - El Forum - 06-08-2009 [eluser]TheFuzzy0ne[/eluser] Is your navigation static or dynamic? Creating a Navigation Site with a Database in CI - El Forum - 06-08-2009 [eluser]crispinatari[/eluser] Its a dynamic site only so i can make changes when need be, its just working out the views and how they relate to each other that is a little tricky at this stage and what is needed in the controller. Creating a Navigation Site with a Database in CI - El Forum - 06-08-2009 [eluser]TheFuzzy0ne[/eluser] OK, let's see if I can clear this up for you at all. In most cases, each controller method has it's own view. You set the variables in the controller method for that view. Within those views, you can include other views, for example: Code: <?php $this->load->view('site_nav'); ?> Assuming your site navigation expects some variables, you can either set those variable from within your controller method, or export the functionality to a model or helper. With a model, you'll most likely make a call to the model method from within each controller method: Code: $data = $this->my_model->get_global_vars(); # I'm assuming that this method returns an array containing all of the global variables that your site navigation uses. With a helper, you can have similar functionality, where the helper calls upon the model, and sets the global variables for your view: Code: function load_global_vars() Does this make anything any clearer? |