include - Including files in index.php (Fat-Free Framework)


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:




and then just normal PHP:

require 'app/globals.php';
require 'app/routes.php';

but it does not work.

This works:


but I do not want to use.cfg files, just.php.




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.

RewriteCond %{REQUEST_URI} \.cfg 
RewriteRule \.cfg$ - [R=404]



File and class inclusion

The Fat Free Way of including files is to use . This can be done in two ways:

(a) setting theAUTOLOAD variable inindex.php:

$f3->set('AUTOLOAD', 'relativepathfromindex/routes.php; relativepathfromindexpath/globals.php');

(b) adding theAUTOLOAD variable to the :

AUTOLOAD=relativepathfromindex/routes.php; relativepathfromindexpath/globals.php

then ensuring theconfig.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 theconfig.ini:



From your file names however you appear to perhaps be using globals, which may include something like:

define("LOGLEVEL", "DEBUG");

The Fat Free Framework does not support this syntax, so use the same method described above using either a set inindex.php (Fat Free recommends switching to CamelCase):

$f3->set('logLevel', 'DEBUG');

or adding it toconfig.ini:



If you want to reference routes outsideindex.php, you will have to amend something like the following:

$f3->route('GET /@controller/@action','@controller->@action');

to a different format as you probably won't have$f3 declared:

Base::instance()->route('GET /@controller/@action','@controller->@action');

People are also looking for solutions to the problem: PHP Database take average and counter


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.