• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What causes the “Twig_Environment not found” error?

#1
I am working on a online newspaper/blogging application with CodeIgniter 3.1.8 and Bootstrap 4. I have decided to add themes to it. The application is not HMVC, only MVC.

I thought it was a good idea to use the Twig template engine to the theme(s). For this purpose, I use CodeIgniter Simple and Secure Twig.


In the third_party directory I have added Twig (version 1.x) itself.

In application\config\autoload.php, I have loaded Twig:

PHP Code:
$autoload['libraries'] = array('database''form_validation''session''user_agent''twig'); 

The problem

In the browser, I get the error:


Code:
Message: Class 'Twig_Environment' not found.
Filename: path\to\root\application\libraries\Twig.php

What am I doing wrong?
Reply

#2
The library should be installed in the ThridParty folder.

Then in you controller.

PHP Code:
// If you don't use Composer, uncomment below
/*
require_once APPPATH . 'third_party/Twig-1.xx.x/lib/Twig/Autoloader.php';
Twig_Autoloader::register();
*/ 

Are you doing that?

Twig for Developers
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
(11-19-2020, 05:05 PM)InsiteFX Wrote: The library should be installed in the ThridParty folder.

Then in you controller.

PHP Code:
// If you don't use Composer, uncomment below
/*
require_once APPPATH . 'third_party/Twig-1.xx.x/lib/Twig/Autoloader.php';
Twig_Autoloader::register();
*/ 

Are you doing that?

Twig for Developers

Yes, I already did all that.
Reply

#4
Isn't third_party libraries loaded through the $autoload['packages'] array? Autoloading libraries only looks for the /application/libraries/* directory, you use the /application/third_party/* directory for this..

Edit:
My mistake, reading to fast on this topic. Sleepy 
You use the correct folder according to the documentation

Do you encounter the same issue when you install the required environment through composer?
Based on the error you give i think the Twig_Environment isn't loaded correctly.
Reply

#5
(11-21-2020, 02:13 PM)superior Wrote: Isn't third_party libraries loaded through the $autoload['packages'] array? Autoloading libraries only looks for the /application/libraries/* directory, you use the /application/third_party/* directory for this..

Edit:
My mistake, reading to fast on this topic. Sleepy 
You use the correct folder according to the documentation

Do you encounter the same issue when you install the required environment through composer?
Based on the error you give i think the Twig_Environment isn't loaded correctly.


I have not tried with Composer and I would rather not. I want the deployment process to be very simple.

Have a look at the GitHub repo

Thanks!
Reply

#6
PHP Code:
@trigger_error('Using Twig_Autoloader is deprecated since version 1.21. Use Composer instead.'E_USER_DEPRECATED); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#7
(11-21-2020, 09:11 PM)InsiteFX Wrote:
PHP Code:
@trigger_error('Using Twig_Autoloader is deprecated since version 1.21. Use Composer instead.'E_USER_DEPRECATED); 


I have switched to Twig-1.2.0 and now I get a "Class 'Twig_Extension_Debug' not found" message.


Filename: path\to\app\application\libraries\Twig.php

Line Number: 131
Reply

#8
(Yesterday, 02:57 AM)Ajax30 Wrote:
(11-21-2020, 09:11 PM)InsiteFX Wrote:
PHP Code:
@trigger_error('Using Twig_Autoloader is deprecated since version 1.21. Use Composer instead.'E_USER_DEPRECATED); 


I have switched to Twig-1.2.0 and now I get a "Class 'Twig_Extension_Debug' not found" message.


Filename: path\to\app\application\libraries\Twig.php

Line Number: 131

Why would you downgrade?
What do you have against composer, it's easier to maintain the packages and versions this way.


You are missing the required classes as the error is telling to you: 'Class {classname} not found'
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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