Wednesday, 15 August 2012

php - How to structure a dynamic website with Codeigniter -


I have some experience with php, but I have recently started learning Codeigniter. I have a website with a fixed navigation pane and sidebar, but the main part of the site is loaded dynamically based on the gate variable. It was originally included .php navbar.php contains the included page in the sidebar.php page included (home, about, contact, etc.) from the included footer. Php

I liked it because the user did not have to reload the whole site while navigating from page to page.

I do not understand how this is done with the codeigner. Should I use a controller for each page for each page, or with each page's function a controller? Does anybody know a good tutorial that does something similar?

Edit: Basically I want to do with Codeigniter,

Since It seems that you want relatively stable content, but are dynamically loaded, what you can do with a controller and (perhaps) a method in the controller.

To do this, with a method, do this in welcome controller:

  public page ($ page_id) {// view / Header.php $ this- & gt; Load-> More; View ("Header"); If ($ page_id = "about") {$ this- & gt; Load-> See ("About"); // see / about.php} and if ($ page_id = "contact") {$ this-> Load-> See ("Contacts"); // view / contact.php} // view / footer.flip $ this-> Load-> Scene ("footer"); }   

It takes a single variable and states what page is being loaded between the header and the footer.

This way, www.yoursite.com/page/about will load this page, will load www.yoursite.com/page/contact contact page

Now, if you want to get rid of the / page section, then you have to start some URL again. Config / routes.php

Alternatively you can use several methods in one controller:

  about public () {// Views / header.php $ this - & gt; Load-> View ("Header"); $ This- & gt; Load-> See ("About"); // view / footer.php $ this- & gt; Load-> Scene ("footer"); } Public contact () {// view / header.php $ this-> Load-> View ("Header"); $ This- & gt; Load-> See ("Contacts"); // view / footer.php $ this- & gt; Load-> Scene ("footer"); }   

Your URLs now look good without routing, but you have to load the header / footer for each page.

No comments:

Post a Comment