• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Layout Class

#1
[eluser]John Nickell[/eluser]
Greetings all,

I am still fairly new to CodeIgniter, but I love what I've been able to do with it so far.

Hopefully my first CodeIgniter library can help someone else, as well.

I know that CodeIgniter already has the ability to load view partials. Also, after looking at some of the templating engines out there, I decided that I wanted to stick with PHP. I was still hoping for some furthur structure/separation.

This library was inspired by:
1. The NetTuts+ tutorial about creating a Layout Manager:
http://net.tutsplus.com/tutorials/php/ho...-tutorial/
2. ASP.NET Master Pages
3. My previous experiences with templating solutions

The syntax I was looking for amounted to this:

Controller:
Code:
<?php
class home extends CI_Controller {
    public function index()
    {
        $this->layout->setTitle('My Site', 'Welcome');
        $this->layout->appendHeadLink('css/style.css');
        $this->layout->view('home', $this->data);
    }
}

Layout:
Code:
<?php print $this->layout->html('doctype'); ?>
<html>
<head>
<title><?php print $this->layout->html('title'); ?></title>
<?php print $this->layout->html('headlink'); ?>
</head>
<body>
<?php print $this->layout->section('header'); ?>
<?php print $this->layout->section('content'); ?>
<?php print $this->layout->section('footer'); ?>
<?php print $this->layout->html('footscript'); ?>
</body>
</html>

The final result is slightly different, but works very well for me so far.

If anyone here might get some use out of it, check it out here:
https://github.com/johnnickell/Layout-Class

Please let me know if you would have done it differently.

Any feedback positive or negative is appreciated.

Thanks!

John Nickell


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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