Fat-Free Framework – 6. Organising controllers in subfolders, routes and namespacing

The namespacing allows us to organize our scripts so that they won’t have conflicts if the classes have the same name and are in different directories. Also, we can group the controllers inside subdirectories.

So how do we do this?

Let’s assume we will have more controllers that we want to group inside the “Users” directory.

For this we will create a “Users” directory inside our “App/Controllers/” directory. Now let us create a Test controller (Test.php) inside our newly created directory:

Reading from the documentation we find out that we need to attach this file to a namespace so let us define it:

Now, all we have to do is create a route towards this new controller. For this we go to our routes.cfg and add a new line:

Now if you visit yoursite.com/testingusers you should receive a “hello” from our framework.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

No spam? * Time limit is exhausted. Please reload CAPTCHA.