• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do you include your pages ?

#1
[eluser]koskoz[/eluser]
Hi everybody,
I'd like to know how do you includes your pages with CI ?
Do you include header, next you've got your content and next your footer, or do you do it an other way ?

Because when I didn't use CI, I did like this :

Code:
HTML Stuff
<?php
$rep = array ("news", "roster", "wars", "contact", "downloads", "palmares", "teams");
            
if(isset($_GET["page"]) && file_exists($_GET["rub"]."/".$_GET["page"] .".php") && in_array ($_GET["rub"], $rep))
   {
       include dirname(__FILE__)."/".$_GET['rub']."/".$_GET['page'].".php";
   }
   else {
       include dirname(__FILE__)."/news/index.php";
        }
?>
HTML Stuff

And I think it's very usefull.

#2
[eluser]Jesse B.[/eluser]
One of the neat features of CI is that it does this kind of logic for you automatically.

Based on your example, you'd have controllers for "news", "roster", "wars", "contact", "downloads", "palmares", and "teams". Within those controllers, you could have methods for "add", "view", "edit", "delete", or whatever makes sense.

The controllers define what your application does. CI performs routing to translate a URL into the appropriate controller and method to call. For example, by default, a URL like this:

Code:
http://example.com/index.php/roster/view/21

...would call the view() method of the roster controller. 21 would be passed as a parameter of view().

When processing is finished, a controller will typically load one or more views, which are like templates for your application. You could make one view per controller, or you could make common views for the site header and footer, and call those in each controller. The choice is based on what makes sense to you.

#3
[eluser]koskoz[/eluser]
I know all that first part Wink

So, the only way to proceed is in the view :

$this_>load->view(header.php);

stuff

$this_>load->view(footer.php);

#4
[eluser]nizsmo[/eluser]
you could look at using some of the nice template libraries available in the wiki, there are several available, and I am using one of them which has a "master template" implementation. In my case then there is no such thing as header and footer, because it is all co-existing in the master template file.

Goodluck Smile

#5
[eluser]koskoz[/eluser]
Oh, nice !
I didn't know that, I'll take a look.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.