[eluser]ryantran[/eluser]
I use Smarty in CI, before embeding Smarty into CI, everything still is ok !
But after embeding, there is an error : parse error
at load template file in controller)
My error :
Parse error: parse error in C:\xampp\htdocs\mysite_application\controllers\home.php on line 24
My structure : mysite + mysite_application + mysite_system, they are same fofder - htdocs folder.
-mysite
index.php
license.txt
-mysite_system
-...
-libraries
-smarty
-libs
Smarty.class.php
-mysite_application
-...
-controllers
home.php
-libraries
smarty.php
-views
-templates
index.tpl
-templates_c
------------------------------------------------------------
-----------------content of smarty.php in mysite_application/libraries/-----------------
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
require_once( BASEPATH.'libraries/smarty/libs/Smarty.class.php' );
class CI_Smarty extends Smarty {
function CI_Smarty()
{
parent::Smarty();
$this->compile_dir = APPPATH . "views/templates_c";
$this->template_dir = APPPATH . "views/templates";
$this->assign( 'APPPATH', APPPATH );
$this->assign( 'BASEPATH', BASEPATH );
log_message('debug', "Smarty Class Initialized");
}
function __construct()
{
parent::__construct();
$this->compile_dir = APPPATH . "views/templates_c";
$this->template_dir = APPPATH . "views/templates";
$this->assign( 'APPPATH', APPPATH );
$this->assign( 'BASEPATH', BASEPATH );
// Assign CodeIgniter object by reference to CI
if ( method_exists( $this, 'assignByRef') )
{
$ci =& get_instance();
$this->assignByRef("ci", $ci);
}
log_message('debug', "Smarty Class Initialized");
}
function view($template, $data = array(), $return = FALSE)
{
foreach ($data as $key => $val)
{
$this->assign($key, $val);
}
if ($return == FALSE)
{
$CI =& get_instance();
if (method_exists( $CI->output, 'set_output' ))
{
$CI->output->set_output( $this->fetch($template) );
}
else
{
$CI->output->final_output = $this->fetch($template);
}
return;
}
else
{
return $this->fetch($template);
}
}
}
-----------------content of home.php in mysite_application/controllers/-----------------
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
// These assignments are passed by the associative array
$data['title'] = 'Welcome to the Smarty Website';
$data['name'] = 'mysite';
$data['message'] = 'Đây là trang home của mysite sử dụng codeigniter framework và smarty template engine'
// Calling the convenience function view() that allows passing data
//$this->smarty->view( 'index.tpl', $data );
}
}
-----------------content of index.tpl in mysite_application/views/templates/-----------------
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{$title} - {$name}</title>
</head>
<body>
<h2>{$message}</h2>
</body>
</html>
that's all. Plx help me !