«   2018/04   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          
Archives
Today
390
Total
1,089,213
관리 메뉴

Blue Breeze

CodeIgniter Stright layout lib - view, js, css 한번에 사용 본문

Framework/PHP-CodeIgniter

CodeIgniter Stright layout lib - view, js, css 한번에 사용

푸른바람 푸른_바람 2016.03.24 12:30


/**
 * @author	: uncaose@gmail.com
 * @url 	: https://github.com/uncaose/straight-ci-layout
 */
class MY_Loader extends CI_Loader
{
	public $_ci_view_path = '';
	public $_views = Array();		// view lists
	public $_skin = '_skin';		// skin
	public $_layout = '_layout';	// layout
	public function __construct()
	{
		parent::__construct();
	}
	// Extend
	public function view( $view, $vars = array(), $return = FALSE )
	{
		$this->_views[] = substr($view, strpos($view, '/')===0?1:0); // 뷰 로드 저장
		return parent::view($view, $vars, $return);
	}
	
	public function getView( $unique=FALSE )
	{
		if( $unique === TRUE )
		{
			return array_unique( $this->_views );
		}
		return $this->_views;
	}
	public function skin( $name='' )
	{
		$this->_skin = $name;
		return $this;
	}
	
	public function getSkin()
	{
		return $this->_skin;
	}
	public function layout( $name='' )
	{
		$this->_layout = $name;
		return $this;
	}
	
	public function getLayout()
	{
		return $this->_layout;
	}
}
/**
 * End Of File application/core/MY_Loader.php
 */
/**
 * @author	: uncaose@gmail.com
 * @url 	: https://github.com/uncaose/straight-ci-layout
 */
class MY_Controller extends CI_Controller
{
	public function __construct()
	{
		parent::__construct();
		if( ! defined('EXT') ) define('EXT', '.php');	// ci2 EXT redefine
		if( ! defined('VIEWPATH')  ) define('VIEWPATH', $this->load->_ci_view_path); // ci3 style
		$this->load->skin('_skin')->layout('_layout');	// default skin, layout
	}
	/**
	 * CI _output
	 */
	public function _output( $output )
	{
		$output = $this->_straight_skin( $output );
		$output = $this->_straight_layout( $output );
		$output = $this->_straight_view( $output );
		
		echo $output;
	}
	
	// skin
	private function _straight_skin( $output='' )
	{
		if( ! empty($this->load->_skin) && file_exists(VIEWPATH.$this->load->_skin.EXT) )
		{
			$output = $this->load->view($this->load->_skin, Array('skin'=>$output), TRUE);
		}
		return $output;
	}
	
	// layout
	private function _straight_layout( $output='' )
	{
		if( ! empty($this->load->_layout) && file_exists(VIEWPATH.$this->load->_layout.EXT) )
		{
			$output = $this->load->view($this->load->_layout, Array('layout'=>$output), TRUE);
		}
		else
		{
			$output = ''.$output.'';
		}
		return $output;
	}
	
	// view
	private function _straight_view( $output='' )
	{
		if( isset($this->load->_views) && sizeof($this->load->getView(TRUE)) )
		{
			foreach( $this->load->getView(TRUE) AS $_view)
			{
				$js = VIEWPATH.$_view.'.js';
				$css = VIEWPATH.$_view.'.css';
				// view js
				if( file_exists( $js ) )
				{
					$js = str_replace(VIEWPATH, 'asset/', $js).'?_='.hash('md5', $js );
					$output = str_replace('', "\n", $output );
				}
				// view css
				if( file_exists( $css ) )
				{
					$css = str_replace(VIEWPATH, 'asset/', $css).'?_='.hash('md5', $css );
					$output = str_replace('', "\n", $output );
				}
			}
		}
		return $output;
	}
}
/**
 * End of File application/library/MY_Controller.php
 */
0 Comments
댓글쓰기 폼