include - Including files in index.php (Fat-Free Framework)
136
I want to include two files (routes.php
andglobals.php
) inindex.php
(Fat Free Framework), but I don't know how.
I have tried require and include the Fat Free way:
$f3=require('lib/base.php');
$f3=require('app/globals.php');
$f3=require('app/routes.php');
$f3=include('app/globals.php');
$f3=include('app/routes.php');
and then just normal PHP:
require 'app/globals.php';
require 'app/routes.php';
but it does not work.
This works:
$f3->config('app/globals.cfg');
$f3->config('app/routes.cfg');
but I do not want to use.cfg
files, just.php
.
Answer
Solution:
If you are afraid of serving your .cfg or .ini files to the clients browser, you can simply forbid that in the shipped .htaccess file.
Answer
Solution:
File and class inclusion
The Fat Free Way of including files is to use
. This can be done in two ways:
(a) setting the
AUTOLOAD
variable inindex.php
:(b) adding the
AUTOLOAD
variable to the:
then ensuring the
config.ini
file is referenced inindex.php
:This is a great way to include all controllers for example in one go by adding something like the following to the
config.ini
:Globals
From your file names however you appear to perhaps be using globals, which may include something like:
The Fat Free Framework does not support this syntax, so use the same method described above using either a set in
index.php
(Fat Free recommends switching to CamelCase):or adding it to
config.ini
:Routes
If you want to reference routes outside
index.php
, you will have to amend something like the following:to a different format as you probably won't have
$f3
declared: