(04-28-2015, 12:57 AM)Vimal Wrote: Greate tell me more.. And what is the library you used in $this->layout ???? I am searching template library
Concerning the Layout it's a library which is auto-loaded and working with an asset helper (also auto-loaded) and layout views.
Layout Class (in application/libraries folder)
PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Layout {
private $CI;
private $data = array();
private $layout = "default";
public function __construct() {
$this->CI =& get_instance();
$this->data["output"] = "";
$this->data["title"] = "Your title here";
$this->data["charset"] = $this->CI->config->item("charset");
$this->data["css"] = array("font-awesome.css", "foundation.css", "toast.css");
$this->data["js"] = array("modernizr.js", "jquery-1.11.2.js", "foundation.min.js", "toast.js", "launchFoundation.js");
}
public function view($name, $data = array()) {
$this->data["output"] .= $this->CI->load->view($name, $data, true);
$this->CI->load->view("layouts/".$this->layout, $this->data);
}
public function setTitle($title) {
if(!empty($title) && is_string($title)) {
$this->data["title"] = $title." - OGMA";
return true;
}
return false;
}
public function setLayout($layout) {
if(!empty($layout) && file_exists(APPPATH.'views/layouts/'.$layout.'.php')) {
$this->layout = $layout;
return true;
}
return false;
}
public function setMenu($menu) {
if(!empty($menu) && is_string($menu)) {
$this->data["menu"] = $menu;
return true;
}
return false;
}
public function addCSS($name) {
if(!empty($name) && file_exists(css_path().$name.".css")) {
$this->data["css"][] = $name.".css";
return true;
}
return false;
}
public function addJS($name) {
if(!empty($name) && is_string($name) && file_exists(js_path().$name.".js")) {
$this->data["js"][] = $name.".js";
return true;
}
return false;
}
}
Asset Helper
Default Layout View (in application/views/layouts folder, you have to create the layouts one)
PHP Code:
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="<?= $charset; ?>" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><?= $title; ?></title>
<?php
foreach($css as $stylesheet) {
echo css($stylesheet);
}
?>
</head>
<body>
<nav>
<menu>
<?= img("logo-small.png", array("alt" => "Logo", "class" => "logo")); ?>
<span class="brand">Brand <small>v1</small></span>
<?= $menu; ?>
</menu>
</nav>
<main>
<?= $output ?>
</main>
<?php
foreach($js as $script) {
echo js($script);
}
?>
</body>
</html>
Then you are free to add for example a menuMaker like I did (it simply use a config array and build all links with the makeMenu() function) or whatever you think would be useful !
I took the Layout Class from the internet but can't manage to find it again so sorry for no credits...