Welcome Guest, Not a member yet? Register   Sign In
Smarty in CI - parse error ? Help me ! :(
#1

[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 Sad 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">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;{$title} - {$name}&lt;/title&gt;



&lt;/head&gt;

&lt;body&gt;
<h2>{$message}</h2>
&lt;/body&gt;
&lt;/html&gt;

that's all. Plx help me !
#2

[eluser]NoticeableDesigns[/eluser]
Missing a ; at the end of

Code:
$data['message'] = 'Đây là trang home của mysite sử dụng codeigniter framework và smarty template engine'

in home.php
#3

[eluser]ryantran[/eluser]
oh...thanks pro ! ^ ^
#4

[eluser]ryantran[/eluser]
with above struture, i place images folder in mysite_application and set
Code:
$config['base_url']    = 'http://'.$_SERVER['HTTP_HOST'].'/mysite_application/';

in home.php controller :
Code:
$data['img_url'] = base_url()."images/";

in index.tpl, i want to show my logo.png in images folder :
Code:
<img src='{$img_url}logo.png'>


to test i did :
Code:
{$img_url}

=> show right url of images folder.

I can understand. Can you help me why ?




Theme © iAndrew 2016 - Forum software by © MyBB