• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Integrate Codeigniter 4.0.2 vs Smarty 3.1.34

#1
Lightbulb 
Hey guys
I'm gonna start my project with CodeIgniter and i need your help to integrate CodeIgniter 4.0.2 vs Smarty 3.1.34
I appreciate your help... Smile
Reply

#2
i fount this tutorial, but it's cofusing 
Translated Link
Reply

#3
Well, this is what I have done to use Smarty according to tutorials.

Downloaded the Smarty to app/ThirdParty/Smarty and created following folders: writable/smarty/templates_c and writable/smarty/cache

app/Libraries/CI4Smarty.php:
Code:
namespace App\Libraries;

require_once APPPATH.'ThirdParty/Smarty/Autoloader.php';

use \Smarty_Autoloader;

Smarty_Autoloader::register();

use \Smarty;

class CI4Smarty extends Smarty {

    public function __construct()
    {
        parent::__construct();
       
        parent::setTemplateDir(APPPATH . 'Views/');
        parent::setCompileDir(WRITEPATH . 'smarty/templates_c/')->setCacheDir(WRITEPATH . 'smarty/cache/');
       
    }

    public function view($tpl_name) {
        if (substr($tpl_name, -4) != '.tpl'){
            $tpl_name.='.tpl';
        }

        parent::display($tpl_name);
    }
}



app/Config/Services.php:
Code:
namespace Config;

use CodeIgniter\Config\Services as CoreServices;
use CodeIgniter\Config\BaseConfig;
use Config\App;
use App\Libraries\CI4Smarty;

require_once SYSTEMPATH . 'Config/Services.php';

class Services extends CoreServices
{
    public static function SmartyEngine($getShared = true){
        return ($getShared === true ? static::getSharedInstance('SmartyEngine') : new CI4Smarty());
    }
};

Controller to return function:
Code:
return service('SmartyEngine')->view('smarty_template.tpl');

This approach (service) avoids to load Smarty every time when your app runs. You can call service('SmartyEngine') in your controller whenever you need to run it.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.