bulton-fr / bfw-controller
Controllers module for BFW
Requires
- bulton-fr/bfw: ~3.0.0-RC11@RC
Requires (Dev)
- atoum/atoum: ~3.1
- atoum/visibility-extension: ~1.3
This package is auto-updated.
Last update: 2024-12-26 02:33:52 UTC
README
Module Controller pour BFW
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.