CodeIgniter Forums
Can't access to config->item from routes.php - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Can't access to config->item from routes.php (/showthread.php?tid=73690)



Can't access to config->item from routes.php - peter - 05-22-2019

Hello,

I created a personal config_cars.php file who is autoload from autoload.php
I can access to my datas like this $this->config->item('') from my controllers but I can't from my routes.php file !

Like this config_cars.php was loaded AFTER routes.php

How to access to my personal config file from routes.php ?

Thank you.


RE: Can't access to config->item from routes.php - bartMommens - 05-24-2019

You can try to define a variable called CAR_CONFIG and load it in your routes like this:

create file car_config:

PHP Code:
$car_config = array(
'route_car' => 'test'
);
//Add whatever data you want to the array and at the end of the file just add:
define('CAR_CONFIG'$car_config

In your routes.php file:

PHP Code:
#include the file
require_once APPPATH.'config/car_config.php';

//Use the variable
$route[CAR_CONFIG['route_car']] = //path to your controller here... 

That should normally work i think Smile