UAP 4 Documentation - BuildingaPage
This tutorial will explain how to build your own custom page for your UAP application. If you are new to UAP, please read MVC Explained to better understand how an MVC works before continuing.
Getting Started
In this tutorial we will create a services page. In this example we want to display what services our website offers. When creating new pages for your application I suggest writing down all your goals for your page.

For this example we are going to create a services page for web design. So we want to write down everything we offer.

- Logo Design
- SEO Optimization
- Site layout and design

We are going to keep it simple for this example, just want to give everyone a good starting point. Now we want to create the files needed to make this page display on our site when we go to our page url. http://www.mywebsite.com/Services
Creating Needed Files
We want to create the following files for our Services pages.

/app/Controllers/Services.php - Controller File
/app/Views/Services/Services.php - View File

We are not going to work with the database in this example, so there is no need to create a Model file.
Building the Controller
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);

	}

}
Building the View
The view is going to be the easiest file to work with for the most part. This is where all of our HTML will be placed. There should be very little of anything other than HTML in the View files. Maybe a little PHP here and there, but for the most part everything else can be loaded with the controller. We are not going to go into much detail on the Services View file, as it is quite simple. For this example we will just echo out the page tile in a card with a little made up data.

<div class="col-12">
	<div class="card mb-3">
		<div class="card-header h4">
			&lt;?php echo $data['title']; ?&gt;
		</div>
		<div class="card-body">
			Logo Design<br>
			Info about Logo Design...<br>
			<br>
			SEO Optimization<br>
			Info about SEO Optimization...<br>
			<br>
			Site Layout and Design<br>
			Info site layout and design...
		</div>
	</div>
</div>
Bring the Page to Life
Now that we have created the files for our Services page we can finish up in the Admin Panel. Login as Administrator and open the UAP Admin Panel.

Select "System Routes" in the Admin Panel sidebar. This page will automatically look through the files in the "app/Controllers" folder and files in the "app/Plugins/*PlugInName*/Controllers" folders. It compares Controllers and Methods to those stored in existing Routes Array. If it does not find a match, the system will add the new Controller and Route to the Routes database. It will use the Method as the URL for the new Route. If the URL is already used on the site it will add a random number to the end of the URL so that it does not have any conflicts.

Once the Auto Router is complete, it will show a success message with details about the new Route. In this case you should get a message like this:

Success! New Routes Have Been Added to Database!

Services - Services
Services - Services Added to Site Links
Click on "Site Links" in the Admin Panel Sidebar. As you can see it added Services to the sample navbar. We can edit the link from this screen if desired.

Everything should be live for the Services page now. To view the page just naviagate to the services page. http://www.mywebsite.com/Services

This tutorial is a good start to build your application. If you have any questions or suggestions please use the Forums.
- Can't find what your looking for? Please use Forum.

UAP 4 Documentation - BuildingaPage

Title
Statistics
Last Reply