| 제목 | hook 을 이용한 layout 설정하기 | ||
|---|---|---|---|
| 글쓴이 | 블루나라 | 작성시각 | 2012/12/05 10:35:52 |
|
|
|||
|
layout file 생성후에 hook 자동 layout 시키는 소스입니다. 디렉토리 : hooks, layouts layouts - default (dir) -- header.php -- footer.php - popup (dir) -- header.php -- footer.php - 2colum -- header.php -- footer.php -- snb - default.php (layout file) - popup.php (layout file) - 2colum.php (layout file) layout file 예제 <br/><b>{yield header}</b>
<br/><b>{yield}</b>
<br/><b>{yield footer}</b>
controller file $CI->yield = TRUE; $CI->layout = 'default';
<br/><b>{yield header}</b>
<br/><b>{yield}</b>
<br/><b>{yield footer}</b>
yield header 안에는 기본적으로 레이아웃의 header 들어가고 없으면 default header가 들어갑니다.이름이 없는 yield 에 실행소스가 들어갑니다.
private function Yield()
{
global $OUT;
$CI =& get_instance();
$output = $CI->output->get_output();
$CI->yield = isset($CI->yield) ? TRUE : FALSE;
$CI->layout = isset($CI->layout) ? $CI->layout : 'default';
if($CI->yield === TRUE)
{
///if(!preg_match('/(.+).php$/', $CI->layout))
$requested = APPPATH.'layouts/'.$CI->layout.EXT;
if(file_exists($requested))
{
$layout = $CI->load->file($requested, true);
$output = str_replace('{yield}', $output, $layout);
if(preg_match_all('/{yield[\s]*([^}]*)}/', $layout, $matches) && array_key_exists(1, $matches))
{
foreach($matches[1] as $k => $v)
{
if(!empty($v))
{
$requested = APPPATH.'layouts/'.$CI->layout.'/'.$v.EXT;
if(!file_exists(FCPATH.$requested))
{
$requested = APPPATH.'layouts/default/'.$v.EXT;
}
$yield = $CI->load->file($requested, true);
$output = str_replace(sprintf('{yield %s}', $v), $yield, $output);
}
}
}
}
}
$OUT->_display($output);
}
>> 민성아빠 ~~~ |
|||
| 다음글 | Active Recode 작성시에 Where 절 문자열... (2) | ||
| 이전글 | print_r 의 변형 함수 (1) | ||
|
한대승(불의회상)
/
2012/12/05 11:00:44 /
추천
0
좋은 정보 감사 합니다.
|
|
리버
/
2013/01/22 01:20:36 /
추천
0
제가 찾던 내용입니다. 감사..
|