Welcome Guest, Not a member yet? Register   Sign In
Really Simple Smarty 3 Library for Codeigniter
#13

[eluser]Alexander84[/eluser]
Frankly saying, I think your Smarty adapter is overbloated.

Here is a light-weight approach step-by-step.

1. Unpack latest Smarty to application/third_party/
2. Drop Mysmarty.php to application/libraries/
3 (optional, for beginners). Drop example.php to application/controllers/
4 (optional, for beginners). Drop example.tpl to application/views/

application/libraries/Mysmarty.php
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
define('SMARTY_DIR', APPPATH.'third_party/Smarty/');
require_once(SMARTY_DIR.'Smarty.class.php');
class Mysmarty extends Smarty
{
    public function __construct ( )
    {
        parent::__construct();
        $config =& get_config( );            
        $this->template_dir   = APPPATH . 'views/';                                                                        
        $this->compile_dir    = APPPATH . 'cache/smarty/compiled/';
        $this->cache_dir      = APPPATH . 'cache/smarty/cached/';
        $this->caching = 2;
    }
    
    function view($resource_name, $params = array())   {
        if (strpos($resource_name, '.') === false) {
            $resource_name .= '.tpl';
        }
        
        if (is_array($params) && count($params)) {
            foreach ($params as $key => $value) {
                $this->assign($key, $value);
            }
        }
        
        if (!is_file($this->template_dir . $resource_name)) {
            show_error("template: [$resource_name] cannot be found.");
        }
        
        return parent::display($resource_name);
    }
}

application/controllers/example.php
Code:
<?php
class Example extends CI_Controller {
    function index()
    {
        $this->mysmarty->view('example');
    }
}

application/controllers/example.tpl
Code:
<!DOCTYPE html>
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Example application - Current time&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    <p>
        — What time is it?<br />
        — It's {$smarty.now|date_format:'%H:%M'} now!<br />
        — Thank you, Sir.
    </p>
&lt;/body&gt;
&lt;/html&gt;

That's all.


Messages In This Thread
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 11-28-2010, 04:40 AM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 12-01-2010, 09:44 AM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 12-01-2010, 04:52 PM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 12-01-2010, 10:01 PM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 12-02-2010, 09:08 PM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 12-02-2010, 09:10 PM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 12-15-2010, 06:30 AM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 01-30-2011, 08:53 AM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 03-11-2011, 11:38 AM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 03-11-2011, 07:00 PM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 03-14-2011, 05:53 PM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 03-14-2011, 08:26 PM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 03-16-2011, 04:04 AM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 03-16-2011, 05:25 AM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 03-16-2011, 10:28 AM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 03-16-2011, 11:06 AM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 03-16-2011, 02:36 PM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 03-16-2011, 04:57 PM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 03-16-2011, 05:43 PM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 04-27-2011, 09:30 AM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 04-27-2011, 02:50 PM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 04-28-2011, 12:11 AM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 04-28-2011, 12:15 AM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 05-08-2011, 01:41 PM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 05-08-2011, 02:54 PM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 05-08-2011, 03:08 PM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 05-08-2011, 08:45 PM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 05-08-2011, 08:48 PM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 05-08-2011, 10:11 PM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 05-08-2011, 10:17 PM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 05-08-2011, 10:19 PM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 05-08-2011, 10:20 PM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 06-22-2011, 06:57 AM
Really Simple Smarty 3 Library for Codeigniter - by El Forum - 06-23-2011, 01:03 PM



Theme © iAndrew 2016 - Forum software by © MyBB