Created
January 31, 2011 10:50
-
-
Save jlebrech/803889 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Layout management library based on: | |
| * http://codeigniter.com/wiki/layout_library/ | |
| * | |
| * Extended layout placeholders and javascript and css files inclussion. | |
| * Author: gbrunacci <gbrunacci *at siamsoft *dot com *dot ar> | |
| */ | |
| class Layout { | |
| var $obj; | |
| var $layout; | |
| var $js; | |
| var $css; | |
| var $placeholder; | |
| var $content_var = 'content'; | |
| var $app_layout_path = 'layouts/'; | |
| function Layout($layout = "default") | |
| { | |
| $this->obj =& get_instance(); | |
| $this->layout = $layout; | |
| $this->js = $this->css = $this->placeholder = array(); | |
| } | |
| function setLayout($layout) | |
| { | |
| $this->layout = $layout; | |
| } | |
| function view($view, $data=null, $return=false) | |
| { | |
| $loadedData = array(); | |
| $loadedData['content'] = $this->obj->load->view($view,$data,true); | |
| if($return) | |
| { | |
| $this->obj->load->_ci_view_path = APPPATH . $this->app_layout_path; | |
| $output = $this->obj->load->view($this->layout, $loadedData, true); | |
| $this->obj->load->_ci_view_path = $this->placeholder; | |
| return $output; | |
| } | |
| else | |
| { | |
| $this->obj->load->_ci_view_path = APPPATH . $this->app_layout_path; | |
| $this->obj->load->view($this->layout, $loadedData, false); | |
| $this->obj->load->_ci_view_path = $this->placeholder; | |
| } | |
| } | |
| function render($html) | |
| { | |
| $this->obj->load->_ci_view_path = APPPATH . $this->app_layout_path; | |
| $loadedData["content"] = $html; | |
| $this->obj->load->view($this->layout,$loadedData); | |
| $this->obj->load->_ci_view_path = $this->placeholder; | |
| } | |
| function load_js($file=null) | |
| { | |
| if(is_array($file)){ | |
| foreach($file as $f) | |
| $this->js[] = $f; | |
| }else $this->js[] = $file; | |
| } | |
| function js() | |
| { | |
| $stream = ""; | |
| foreach($this->js as $js){ | |
| $stream .= '<script type="text/javascript" src="/js/'. $js .'.js" ></script>' . "\n"; | |
| } | |
| return $stream; | |
| } | |
| function load_css($file=null) | |
| { | |
| if(is_array($file)){ | |
| foreach($file as $f) | |
| $this->css[] = $f; | |
| }else $this->css[] = $file; | |
| } | |
| function css() | |
| { | |
| $stream = ""; | |
| foreach($this->css as $css){ | |
| $stream .= '<link href="/css/'. $css .'.css" rel="stylesheet" type="text/css" media="screen" />' . "\n"; | |
| } | |
| return $stream; | |
| } | |
| function placeholder($key, $value=null){ | |
| if($value==null){ | |
| if(isset($this->placeholder[$key])){ | |
| return $this->placeholder[$key]; | |
| } else { | |
| return "<!-- missing placeholder:" . $key . " -->"; | |
| } | |
| } else { | |
| $this->placeholder[$key] = $value; | |
| } | |
| } | |
| } |
Author
jlebrech
commented
Jan 31, 2011
// rendering without a view but with the layout.
$this->layout->render("hello");
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment