Controllers

Sprnva is a MVC approach so we also have a Controller which all the logics of our page is stored and processed.

Controller is the medium where logic, database and view meet. Controller also is the processing area of all the logics to be fetch later in the views.

You will find the controller at app/controllers. Then this is how you declare a basic controller.

<?php

namespace App\Controllers;

class WelcomeController
{
    protected $pageTitle;

    public function index()
    {
        $pageTitle = "Home";

        return view('/home', compact('pageTitle'));
    }
}

ALWAYS REMEMBER WHEN ADDING A CLASS, DON'T FORGET TO ADD IT'S NAMESPACE AND RE-INITIALIZE THE CLASS AUTOLOADER USING COMPOSER.

This is how you re-initialize class autoloader using composer.

composer dump-autoload

Last updated