bulton-fr/bfw-controller

Controllers module for BFW

3.0.0-rc.11 2016-10-08 00:00 UTC

README

Module Controller pour BFW

Build Status Coverage Status Scrutinizer Code Quality Latest Stable Version License

Install :

You can use composer to get the module : composer require bulton-fr/bfw-controller @stable

And to install the module : ./vendor/bin/bfwInstallModules

Config :

All config file for this module will be into app/config/bfw-controller/. There are one file to configure (manifest.json is for the module update system).

The file config.php

  • useClass : Define if all controller will be classes (true) or procedural file (false).

Use it :

Create your controller files into the directory /src/controllers.

For an object controller, you can extends from the class \BfwController\Controller. This class adding properties $app and $request who are a direct access to the instance of the classes \BFW\Application and \BFW\Request. You can use the namespace \Controller, it's added by the framework and corresponding to the directory /src/controllers.

For a procedural controller, the file will be included into a closure who is into the method \BfwController\BfwController::runProcedural(). So you will have a direct access to $this of the class, and you will have variables $routerLinker and $controllerFile into the scope.

Example :

Extract from the BFW wiki, an exemple with an object controller.

<?php

namespace Controller;

class Test extends \BfwController\Controller
{
    public function index()
    {
        var_dump($this->request->getRequest());
    }
}

Router module :

This module not manage the application routing. You need to add a router module too.

The route module have a config file to define each route. For each route, you should define a "target". With bfw-controller, the "target" value should have a specified format :

  • For an object controller : An array, the first value should be the class name (with namespace), the second value the method name. Like a callable array.
  • For a procedural controller : The filename with this extension. The path to the directory /src/controller should be omitted.