Controllers are placed inside the src/controller directory. As a convention all controller names have to end on Controller.php. Actions contained in there must end on Action. For instance we create a src/controller/indexController.php file with the following content:


namespace src\controller;

class indexController extends \hubert\generic\controller {

    public function indexAction($params){
        return $this->responseTemplate("index/index", ["name" => "Hubert"]);

    public function apiAction(){
        $data = ["users" => ["Falk", "Ronny"]];
        return $this->responseJson($data);

    public function redirectAction(){
        $home_route = hubert()->router->get("home");
        return $this->responseRedirect($home_route);


Controllers inherit from \hubert\generic\controller or you implement your own interface at hubert\interfaces\controller. The response object is avaliable using $this->getResponse() and the request object is available using $this->getRequest(). Controllers always have to return a response object. To populate it with some data there are three ways to do so: