kenjis / codeigniter-ss-twig

A Simple and Secure Twig integration for CodeIgniter 3.x and 4.x
MIT License
168 stars 46 forks source link

ERROR: Class 'CI_Twig' not found #26

Closed parinisantiago closed 7 years ago

parinisantiago commented 7 years ago

Hi @kenjis,

I installed codeigniter-ss-twig and work very well, but for some reason I get this error:

Fatal error: Class 'CI_Twig' not found in /path/to/codeigniter/system/core/Common.php on line 196

Here it's a screenshot of the problem:

errortwig

it's related to the librarie? Any help?

kenjis commented 7 years ago
  1. How did you setup this codeigniter-ss-twig? With Composer or without Composer?
  2. Do you call a controller from another controller?
parinisantiago commented 7 years ago

I install codeigniter-ss-twig and twig with Composer. Also I call a controller from another controller. My Class herarchy look something like this:

class MainController extends Controller
{
    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        if(Session::userLogged())
        {
           $this->controller= new BackendController();
           $this->controller->index();
        } else {
            $this->render('MainTemplate');
        }
    }
}
class BackendController extends Controller{

    public function __construct(){
            parent::__construct();
    }

   public function index(){
           $this->render('BackendTemplate');
   }
}
class Controller extends CI_controller
{

    protected $data;

    protected function __construct(){
        parent::__construct();
    }

    protected function render($view){
          $this->load->library('twig');
          $this->twig->display($view,$this->data);
    }

My default controller is MainController, when this controller is called for first time it's works fine but then when I make a call to another controller i get that error.

kenjis commented 7 years ago

This is because of CodeIgniter's specification. That is you can't call another controller from a controller.

murugappanrm commented 4 years ago

This reply is wrong. In Codeigniter you can call one controller from another controller. This does not work only because of twig. There is something wrong in the twig integration with Hmvc.

kenjis commented 4 years ago

In Codeigniter you can call one controller from another controller.

You could call, but CI does not work like what you want. See https://stackoverflow.com/questions/14165895/how-to-load-a-controller-from-another-controller-in-codeigniter.

murugappanrm commented 4 years ago

In Codeigniter you can call one controller from another controller.

You could call, but CI does not work like what you want. See https://stackoverflow.com/questions/14165895/how-to-load-a-controller-from-another-controller-in-codeigniter.

The stackoverflow link you have given is dated 4 years or older. I am using PHP 7, CI 3.1.11 and HMVC revamp and Twig 2.0 and these solutions dont fit. Anyway i fixed it already. I used the CI "redirect" function and "flashdata" combination instead. This works fine. I have attached the modules here:

modules.zip