Google News
logo
FuelPHP - Interview Questions
What about Namespacing controllers in FuelPHP?
As mentioned in the introduction, by default controllers are created in the APPPATH/classes/controller folder, and are prefixed with Controller_. This prefix is defined in your APPPATH/config/config.php configuration file (and if not this is the default), but can be changed if you want to namespace your controllers, or if you want to move them to a different folder structure.
 
Let's move the example given above to the Controller namespace. You tell FuelPHP that you've done this by setting the config setting controller_prefix from 'Controller_' to 'Controller\\' in your app's config.php file.
namespace Controller;

class Example extends \Controller
{
    public function action_index()
    {
        // some code here
    }
}
Once you have enabled namespacing for your controllers, ALL your controller classes need to be namespaced! This means a controller in a module called Mymodule will look like this :
namespace Mymodule\Controller;

class Example extends \Controller
{
    public function action_index()
    {
        // some code here
    }
}
Advertisement