<?php
/**
* Parser Class
*
* Created on 2011. 11. 16.
* @author 불의회상 <hoksi2k@hanmail.net>
* @package library
* @subpackage controllers
* @version 1.0
*/
class Parser_lib extends CI_Controller {
var $data;
var $tpl;
function __construct() {
parent::__construct();
$this->load->library('parser');
$this->data = array(
'blog_title' => 'My Blog Title',
'blog_heading' => 'My Blog Heading',
'blog_entries' => array(
array('title' => 'Title 1', 'body' => 'Body 1'),
array('title' => 'Title 2', 'body' => 'Body 2'),
array('title' => 'Title 3', 'body' => 'Body 3'),
array('title' => 'Title 4', 'body' => 'Body 4'),
array('title' => 'Title 5', 'body' => 'Body 5')
)
);
$this->tpl = '{blog_title}';
}
function index()
{
$this->load->view('parser_lib_sample', $this->data);
}
function template_parser()
{
// Template 문자열 파싱 후 변수에 저장
// 3번째 옵션을 FALSE로 할 경우 화면에 바로 출력 함
// 문자열을 파싱 할 경우 템플릿 문자열이 결과 값으로 바뀜(응? ㅡ,.ㅡ;;;;;)
$this->parser->parse_string($this->tpl, $this->data, TRUE);
// Template 파일 파싱 후 출력
$this->parser->parse('parser_lib_sample', $this->data);
}
}
<?php $this->load->view('inc/header')?>
<table class="tablesorter" border="0" cellpadding="0" cellspacing="1">
<thead>
<tr>
<th style="text-align:center" colspan="2">Template Parser</th>
</tr>
</thead>
<tr>
<td colspan="2">
<input type="button" class="btn" value="Template 보기" onclick="document.location.href='<?=site_url('parser_lib')?>'" />
<input type="button" class="btn" value="Template 파싱" onclick="document.location.href='<?=site_url('parser_lib/template_parser')?>'" />
</td>
</tr>
<thead>
<tr>
<th style="text-align:center" width="20%">구분</th>
<th style="text-align:center">결과</th>
</tr>
</thead>
<tr>
<td width="20%">Template</td>
<td>
<xmp>
<h1>{blog_title}</h1>
<h3>{blog_heading}</h3>
{blog_entries}
[{title}] {body}<br/>
{/blog_entries}
</xmp>
</td>
</tr>
<tr>
<td>String Template</td>
<td><?php echo $this->tpl?></td>
</tr>
<tr>
<td>Data</td>
<td><xmp><?php print_r($this->data)?></xmp></td>
</tr>
</table>
<?php $this->load->view('inc/footer')?>
© Copyright by hoksi(Page rendered in 0.0049 seconds)