9. Controller
The Controller must implements the ControllerInterface, which is very simply:
interface ControllerInterface {
function handle(Request $Req, Response $Res);
}
The framework has 2 predefined controllers implementation classes, which should be enough for the 99% of application development use case, the AbstractController and the ActionController. Both of them have important behaviours and functionalities that can reduce the amount of code to be developed, providing you some sensible defaults and shortcuts.
To extends AbstractController, this is an example:
class MyController extends \metadigit\core\web\controller\AbstracController {
function doHandle(Request $Req, Response $Res) {
// .. do stuff
}
}
To extend ActionController, this is an example:
class MyActionController extends \metadigit\core\web\controller\ActionController {
function exampleAction(Request $Req, Response $Res) {
// .. do stuff
}
function otherAction(Request $Req, Response $Res) {
// .. do stuff
}
}
More about the ActionController later, for now just remember that both of them have implementation methods with the same signature.
Updated about 1 month ago