Welcome Guest, Not a member yet?
 What causes the “Twig_Environment not found” error? Ajax30Member Posts: 68 Threads: 43 Joined: Aug 2017 Reputation: 11-19-2020, 06:52 AM (This post was last modified: 11-20-2020, 08:54 AM by Ajax30.) 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? InsiteFXSuper Moderator Posts: 4,986 Threads: 128 Joined: Oct 2014 Reputation: 11-19-2020, 05:05 PM (This post was last modified: 11-19-2020, 05:07 PM by InsiteFX.) 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 ) .pborder { border-top: 1px dashed #ccc; padding-bottom: 10px; margin: 15px; } Ajax30Member Posts: 68 Threads: 43 Joined: Aug 2017 Reputation: 11-20-2020, 01:30 AM (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. superiorCoding is Art Posts: 83 Threads: 20 Joined: Oct 2016 Reputation: 11-21-2020, 02:13 PM (This post was last modified: 11-21-2020, 02:19 PM by superior.) 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.   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. Ajax30Member Posts: 68 Threads: 43 Joined: Aug 2017 Reputation: 11-21-2020, 04:19 PM (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.   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! InsiteFXSuper Moderator Posts: 4,986 Threads: 128 Joined: Oct 2014 Reputation: 11-21-2020, 09:11 PM 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 ) .pborder { border-top: 1px dashed #ccc; padding-bottom: 10px; margin: 15px; } Ajax30Member Posts: 68 Threads: 43 Joined: Aug 2017 Reputation: 11-22-2020, 02:57 AM (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[font=Times New Roman]\to[font=Times New Roman]\app[/font]\application\libraries\Twig.php[/font] Line Number: 131 superiorCoding is Art Posts: 83 Threads: 20 Joined: Oct 2016 Reputation: 11-23-2020, 03:11 AM (11-22-2020, 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[font=Times New Roman]\to[font=Times New Roman]\app[/font]\application\libraries\Twig.php[/font] 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'