Piotr Żęgota
Piotr Żęgota

Reputation: 51

CodeIgniter + Smarty

I have a problem with connecting CI and Smarty. I make everything in this manual, but when I try open a page I see:

Fatal error: Uncaught --> Smarty: Unable to load template file 'view/index.tpl' <-- thrown in /opt/lampp/htdocs/ci/application/libraries/smarty/libs/sysplugins/smarty_internal_templatebase.php on line 129

Where I can change destination folder?

I also want to add, that I made a view file in the views folder.

Upvotes: 0

Views: 2307

Answers (2)

Luca Mori Polpettini
Luca Mori Polpettini

Reputation: 596

That manual is for CodeIgniter 2. Update to CodeIgniter 3 and follow these steps:

  1. Download CodeIgniter 3
  2. Download Smarty 3 and put its content in 'application/third_party/smarty' folder
  3. Create 'Custom_smarty.php' file in 'application/libraries' and add this code:

    <?php
    if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    require_once(APPPATH.'third_party/smarty/Smarty.class.php');
    
    class Custom_smarty extends Smarty {
    
      function __construct()
      {
        parent::__construct();
        $this->setTemplateDir(APPPATH.'views/templates/');   
        $this->setCompileDir(APPPATH.'views/templates_c/');
      }
    }
    ?>
    
  4. Create 'templates' & 'templates_c' folders inside 'application/views' folder

  5. Create simple 'test.tpl' file in 'application/views/templates' folder
  6. Open 'autoload.php' in 'application/config' folder and add:

    $autoload['libraries'] = array('custom_smarty');
    
  7. Inside a controller write $this->custom_smarty->display('test.tpl');

  8. If you are working on localhost set the permissions: sudo chmod -R 777 templates_c. Otherwhise contact your hosting service, if you catch the error Unable to write file. First be sure templates_c folder exists.

Upvotes: 4

Piotr Żęgota
Piotr Żęgota

Reputation: 51

Ok, i find. It's view/templates but i have a new error message.

Fatal error: Uncaught --> Smarty: unable to write file application/views/compiled/wrt549692a6e7c983_16652543 <-- thrown in /opt/lampp/htdocs/ci/application/libraries/smarty/libs/sysplugins/smarty_internal_write_file.php on line 46

I create a view/compiled folder but smarty cant make file them(?) perrmissions(?)

EDIT. Ok, all is ok. I dont have permissions for few folders.

Upvotes: 0

Related Questions