The controller is going to collect the backend data for the view.
When a page is opened, this is the first place that the framework
looks to find out what to display to the users. Since this is going
to be a simple public page, we do not need a bunch of code. We want
to create a Controller class for services and a method function
within that class.
The first thing we want to do, is set the location of the file we
are working on. Basically which folder the file is in. We created
Services.php in the /app/Controllers folder. The router for the
framework is set to read the app folder as "App". We want to reflect
the case of App in our namespace.
<?php
namespace App\Controllers;
Now we want to include the System Controller, and System Load files
so that the page will load properly. We can also include Libraries
and Models if needed. In this case we don't need any extra files.
We will include the needed files with the "use" function.
use App\System\Controller,
App\System\Load;
Now we want to setup the Services class. This class will extend the
System Controller. The class will look like this:
class Services extends Controller {
}
Next we want to create a Services function. The site router will
take the URL and search for which Controller and Method to load. In
this case it will look in the Services Controller Class for the
Services Function Method and run that function. This is what the
function will look like:
public function Services(){
}
The UAP Framework is designed to look for the page title and
description for each page. We can declare each within the Services
Function like so:
$data['title'] = "My Services Title";
$data['description'] = "We offer top of the line Web Design Services description.";
Since this page is going to be simple all we have left to do is add
the View Loader. This will pull the View file that all page data
will be sent to. This can be customized to fit your needs with a
wide range of options. For this example we are going to keep it
plain and simple and just load the View file itself.
Load::View("Services::Services", $data);
Here is what your /app/Controllers/Services.php file should look like
now with some added comments.
<?php
namespace App\Controllers;
/* Includes */
use App\System\Controller,
App\System\Load;
/* Services Pages Controller Class */
class Services extends Controller {
/* Services Method */
public function Services(){
/* Page Data */
$data['title'] = "My Services Title";
$data['description'] = "We offer top of the line Web Design Services description.";
/* Push data to the view */
Load::View("Services::Services", $data);
}
}