-
Notifications
You must be signed in to change notification settings - Fork 0
mpage
You know, django is a good python framework.And in django, you can master page. For example:
base.html (Our layout page) [code]<html> <head><title>{% block title %}{%endblock%}</title></head> <body> text text text lorem ipsom dolar is amet bla bla bla {% block content %}{% endblock%}
Footer code bla bla </html>[/code]
a page simple.html We can include layout page like this [code]{% extends 'base.html'%}
{%block title%}Page Title{%endblock%} {%block content%}This is the content{%endblock%}[/code]
OK.We use that in page with mPage library:
You can add this to your construct function or a function :D of course into your controller [code] $this->load->library("mpage"); // Defining base page $this->mpage->base("base"); # Will be: views/base.php
// a function function alpcan() { $data['variable'] = "i love CI"; $data['second'] = "php is the best"; // not $this->load->view("simple", $data); $this->mpage->render("simple", $data); } [/code]
And last base.php and simple.php in views directory base.php: [code]<html> <head> <title> <block=title> </title> </head> <body> text text text lorem ipsom dolar is amet bla bla bla <block=content> </body> </html>[/code]
If you don't know master page you can look at to google :P Finally sorry for my bad english Alpcan AYDIN - [email protected]
And mPage.php: [code] <?php /**
- @author: Alpcan AYDIN [email protected]
- @copyright: 2008 Batikon Internet Technologies(c)
- @version: v0.1
- For your suggestions send a mail to [email protected] */
// We create a class which name is mPage class mPage { /** * Definition: Base Page * * @var string */ private $base = "";
/**
* Definition: Sub Page
*
* @var string
*/
private $subPage;
/**
* Definition: Error Text
*
* @var string
*/
private $errorText;
/**
* Definition: CodeIgniter
*
*/
private $CI;
/**
* Definition: Construct Function
*
* @param none
*/
public function __construct() {
// We include CodeIgniter Libraries
$this->CI = get_instance();
}
/**
* Definition: Error Function
*
* @param errorText
*/
protected function error($errorText) {
if(!empty($errorText)) {
$this->errorText = $errorText;
$styleText = "padding:3px; margin:3px; border:2px solid #C00606; background:#FCFBA7;";
$styleText.= "color:#cc0000; font-family:verdana; font-size:11px;";
echo "<div style='$styleText'><b>mPage Error:</b> $this->errorText</div>";
}
}
/**
* Definition: Set Base Page
*
* @param base
*/
public function base($base) {
// Control: is file exist?
if(file_exists(APPPATH.'views/'.$base.EXT)) {
// Defined base path
$this->base = $base;
}else {
// Give error
self::error("Can't found <b>$base".EXT."</b> in views directory");
}
}
/**
* Definition: Render
*
* @param subPage, tags, content
*/
public function render($subPage, $content = array()) {
// Base Page
$basePage = $this->CI->load->view($this->base, $content, TRUE);
// if sub page exist
if(file_exists(APPPATH.'views/'.$subPage.EXT)) {
$subPageSOURCE = $this->CI->load->view($subPage, $content, TRUE);
preg_match_all('/\<block\=(.*?)\>(.*?)\<\/block\>/s', $subPageSOURCE,$subTag);
for($i=0; $i<=count($subTag[1]); $i++) {
$tags = $subTag[1][$i];
$tagContent = $subTag[2][$i];
$basePage = str_replace('<block='.strtolower($tags).'></block>', $tagContent, $basePage);
}
preg_match_all('/\<block\=(.*?)\>(.*?)\<\/block\>/s', $basePage,$exTags);
for($i=0; $i<=count($exTags[1]); $i++) {
$exTag = $exTags[1][$i];
$basePage = str_replace('<block='.strtolower($exTag).'></block>', "", $basePage);
}
}else {
self::error("Can't found <b>$subPage".EXT."</b> in views directory");
}
echo $basePage;
}
}
?> [/code]