Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (!defined('BASEPATH')) exit('No direct script access allowed');
- /**
- * Layout class for creating default page layouts.
- *
- * This class will allow you to use a layout file so you won't need to include
- * the consistent blocks of code throughout your template files.
- *
- * @author The Sweeney <jfmike@gmail.com>
- */
- class Layout Extends CI_Controller {
- /**
- * The controller object for the calling class
- *
- * @var object
- * @access private
- */
- private $obj;
- /**
- * The layout filename (with or w/out the '.php' at the end)
- *
- * @var string
- * @access private
- */
- private $layout;
- /**
- * The default controllers to include. It can be overwritten if necessary.
- *
- * @var array
- * @access public
- */
- public $defaults = array('header','footer');
- /**
- * Create an Instance, optionally deciding which layout to use.
- *
- * @param string $layout A string that points to the default layout file.
- * Defaults to /layouts/layout_main.php which will be located in /application/views.
- */
- public function __construct($layout = "/layouts/layout_main") {
- $this->obj =& get_instance();
- $this->layout = $layout;
- }
- /**
- * Set the layout to use a different layou than the default main layout
- *
- * @param string $layout A string that points to the location to the layout file you wish to use.
- */
- public function setLayout($layout) {
- $this->layout = $layout;
- }
- /**
- * A semi-recursive method to load a view inside the layout.
- *
- * @param string $view location to view file
- * @param array $data The data to load into the view file
- * @param booleanl $return A boolean to let the method know whether or not to call itself or stop processing.
- *
- * @return string $output The html output string
- *
- * @see CI_Loader::view()
- */
- public function view($view, $data=null, $return=false) {
- $loadedData = array();
- $loadedData['content'] = $this->obj->load->view($view,$data,true);
- if($return) {
- $output = $this->obj->load->view($this->layout, $loadedData, true);
- return $output;
- } else {
- $this->obj->load->view($this->layout, $loadedData, false);
- }
- }
- /**
- * A replacement for the view function if the CI templating classes are being used
- *
- * @param string $template The template to load.
- * @param array $data The array of data to load into the file to be parsed
- * @param boolean $return A boolean to let the method know whether or not to call itself or stop processing.
- *
- * @return string $output The html output string
- *
- * @see Layout::view()
- */
- public function parse($template, $data=null, $return=FALSE) {
- $loadedData = array();
- $loadedData['content'] = $this->obj->parser->parse($template,$data,true);
- if ($return) {
- $output = $this->obj->parser->parse($this->layout, $loadedData, true);
- return $output;
- } else {
- $this->obj->parser->parse($this->layout, $loadedData, false);
- }
- }
- }
Add Comment
Please, Sign In to add comment