«   2018/10   »
  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 31      
Archives
Today
361
Total
1,167,520
안정적인 DNS서비스 DNSEver
관리 메뉴

Blue Breeze

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

Language/PHP

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

푸른바람 C/H 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
 */

'Language > PHP' 카테고리의 다른 글

composer 프로젝트 셋업  (0) 2016.04.04
Composer Install  (0) 2016.03.30
CodeIgniter Stright layout lib - view, js, css 한번에 사용  (0) 2016.03.24
PHP SocketIOClient.php On socket.io 1.3.7 Error  (1) 2015.12.02
동영상 업로드  (0) 2015.08.21
PHP 웹 사이트 IDE 개발툴  (0) 2015.06.01
0 Comments
댓글쓰기 폼