Application - Controller
#Controller
#Overview
The best of Architectural patterns is Model–View–Controller(MVC) these day. I thing that the Controller is the best important of them. The controller in part of framework is a powerful library as well. the CL's Controller can receives user's request data and demand to MODEL(the Model of MVC) in order to get data from a database system and send these data to the Response(the View of MVC) .
How To Use
The controller should be received something via the route. (Flow : index.php -> route -> controller ). You have to need 2 PHP files(route file, controller file) at least
#PHP Code
<?php
use CafeLatte\Core\Controller;
use CafeLatte\Interfaces\ControllerInterface;
use CafeLatte\Interfaces\HttpRequestInterface;
use CafeLatte\Interfaces\LoggerInterface;
class ControllerClassName extends Controller implements ControllerInterface
{
public function __construct(HttpRequestInterface $request, LoggerInterface $log)
{
parent::__construct($request, $log);
}
public function testMethod()
{
//Write your PHP code here(GET/POST/DELETE/PUT);
// 1.REQUEST CODE;
// 2.VALIDATION CODE;
// 3.MODEL(MODEL of MVC);
// 4.RESPONSE(VIEW of MVC);
}
}
* You can change class name whatever you want, such as "MyTestController", "MemberController", "LoginController" , "TokenController"
#Full Example
The controller should be received something via the route. (Flow : index.php -> route -> controller ). You have to hav 2 PHP file at least
#PHP Code
index.php
<?php
class MyTestIndex extends \CafeLatte\Core\BaseRoute implements \CafeLatte\Interfaces\RouterInterface
{
public function routing()
{
$this->router->get("", function () {
$this->result = (new MyTestController($this->request, $this->log))->testMethod();
});
//DO NOT REMOVE
$this->router->run();
}
}
$framework = new MyTestIndex();
$framework->execute();
MyTestController.php
<?php
use CafeLatte\Core\Controller;
use CafeLatte\Interfaces\ControllerInterface;
use CafeLatte\Interfaces\HttpRequestInterface;
use CafeLatte\Interfaces\LoggerInterface;
class MyTestController extends Controller implements ControllerInterface
{
public function __construct(HttpRequestInterface $request, LoggerInterface $log)
{
parent::__construct($request, $log);
}
/**
* Mapping method name
*/
public function testMethod()
{
//Write your PHP code here(GET/POST/DELETE/PUT)
}
}
#Tutorial
To get more information, move to tutorial page, Click `Here`