4

I would like to set a global variable called CONTROLLERPATH in my config.ini file and then use that variable in my index.php file to route the GET requests to the correct controller in my directory structure. I am doing the following and F3 cannot make out the value of CONTROLLERPATH.

My config.ini file:

[global]

DEBUG=3
UI=ui/
CONTROLLERPATH='app/controllers/'

Within my index.php file:

$f3->config('config.ini');
$f3->route('GET /', CONTROLLERPATH . 'indexController->index');

I have also tried to ditch the config.ini way and setting the value of controllerPath as follows in my index.php file, and it still does not work:

$f3->set('controllerPath', 'app/controllers/');
whistler
  • 876
  • 2
  • 15
  • 31

1 Answers1

5

Variables defined in ini files are framework variables, not PHP constants.

It means that they are accessible via the framework, using one of the following syntaxes:

  • $f3->get('CONTROLLERPATH')

  • $f3['CONTROLLERPATH']

  • $f3->CONTROLLERPATH

xfra35
  • 3,833
  • 20
  • 23
  • Very helpful! When I use the CONTROLLERPATH as a framework variable, it is still not working if I try to concatenate within the routing as follows: $f3->route('GET /', $f3->CONTROLLERPATH . 'indexController->index'); I just need a way to tell F3 that all of my controllers are in the app/controllers folder – whistler Jan 15 '15 at 17:44
  • PHP namespaces are identified by *backslashes* not forward slashes. So your ini entry should rather look like `CONTROLLERPATH = app\controllers\ ` (notice also how single quotes are not required). Also your file structure should follow the [autoloader](http://fatfreeframework.com/routing-engine#the-f3-autoloader) requirements (see this [answer](http://stackoverflow.com/questions/27262719/implementing-namespaces-in-fatfree-framework/27312633#27312633) for more details). – xfra35 Jan 15 '15 at 17:54