Skip to content

Latest commit

 

History

History
executable file
·
49 lines (35 loc) · 1.04 KB

8.2HomeController.php.md

File metadata and controls

executable file
·
49 lines (35 loc) · 1.04 KB

Criar a classe HomeController

Acesse a pasta

/var/www/html/app-mvc/src/Controller

E crie o arquivo

HomeController.php

Com o conteúdo abaixo:

<?php

/**
 * Class HomeController
 *
 * Please note:
 * Don't use the same name for class and method, as this might trigger an (unintended) __construct of the class.
 * This is really weird behaviour, but documented here: http://php.net/manual/en/language.oop5.decon.php
 *
 */

namespace Mvc\Controller;

class HomeController
{
    /**
     * PAGE: index
     * This method handles what happens when you move to http://yourproject/home/index (which is the default page btw)
     */
    public function index()
    {
        // load views
        require APP . 'view/_templates/header.php';
        require APP . 'view/home/index.php';
        require APP . 'view/_templates/footer.php';
    }

}

Experimente atualizar o navegador agora

Ele encontrou o Home controller e agora reclama da execução do método index, pois ele espera que a view respectiva esteja pronta para abrir.

Continuemos.