Quick Start

Installation

Gliver Framework requires PHP version 7.0 or greater to run. In order to avoid broken functionality or open security holes in your application, upgrade to version >=7.0

You also need to have Composer installed on your computer in order to be able to install the Gliver framework

Gliver framework uses .htaccess rules to process requests so ModeRewrite should be enabled on your server.

Step 1.

Click here to Download Gliver from GitGub and extract it in your root directory<

Step 2.

Run 'composer update' from the root directory of your Gliver installation to install the Gliver framework dependencies

composer update

Step 3.

Alternatively, can install Gliver framework directly from Packagist repository by running 'composer create-project gliver/gliver myapp' in from command line

composer create-project gliver/gliver myapp

This command would download the latest stable version of Gliver framework and all dependencies and install them in the directory myapp.

You can change the name of the directory to your directory of choice, or better still rename it after installation...

Configuration

There are four configuration files where you can specify the settings for your application.

These options can be accessed from anywhere within your application using specific class methods.

Config.php

This file contains the general configuration options of your application.

The config.php resides in the config directory.

config/config.php

Set the value of 'dev => true' if your application is running in development mode and set this to 'false' as soon as you deploy to production.


'dev' => true,
  

This would do is to ensure that error messages are not shown to the user when in production mode in order to avoid exposing your server directory structure to that malicious jerk.

Useful Tip:

Define your default controller and method pair for your entire application here.

These are key as they will be loaded as your homepage i.e. whenever you access you application without specifying the controller and method


/**
 *Default controller
 */
'controller' => 'Home',
/**
 *Set default method
 */
'action' => 'Index' 

Database.php

The Gliver database configuration file resides in the config directoty.

config/database.php

In the database configuration, you can specify the settings for any supported database then specify the default database you would like the application to alwasy connect to.

As soon as you change your mind and would like to use a different database, just set it as the default.


/**
 *Define the database server hostname
 */
'host'    => 'localhost',
/*
 *Define the username
 */
'username'  => 'root',
/*
 *Define the database password
 */
'password'  => '',  

Constants.php

The constants configuration file resides in the application directoy.

application/constants.php

Here you can define all the values that you will need throughout all your application.

Once defined, you can access them from anywhere in your application by using the constant name.


//Specify the network id constant
define('NETWORK_ID', 'gliver'); 

You can then access them from anywhere in this manner:

 
echo NETWORK_ID; 

Routing

The routing feature enables mapping of defined keywords to particular controllers/action pairs.

Routing also enables you to pass url parameters to your controllers which it parses and includes as part of the GET parameters you access them via the Input helper class.

The routing class gives much flexibility so that you can map a defined route to a controller, a controller method pair and optionally name the parameters that you expect to recieve along with the url request

Routes are defined in the routes.php file found in the application directory.

application/routes.php

Defining routes is, however, optional as you can decide to call your controllers directly from the url and pass unamed parameters and accessing them using numbered indexes.

Remember that the routes.php file is an array and therefore should maintain a valid array format.

Say you have a controller class named LoadController that you would like to invoke using the word blog.

In order to achieve this you will define this name value pair in the routes file as:


"blog" => "Load",

This simply means the word blog maps to the LoadController class, so that when you access the LoadController class from the url you use the word blog in this manner:

http://localhost/myapp/blog

If you define a route to map to a controller without specifying a method pair, you can still supply the method name as the second parameter in the url. Otherwise the default method name set in your config.php would be excecuted whenever this route is accessed.

If you want to define a route that maps to a controller class with the particular method to be executed, separate the controller class and method name with an @ symbol.

Say you have an AdminController class that loads users profiles using a getUser() method.

You can define an 'adminusers' route that maps to this controller class and the getUser() method in order to load a user's profile.

It would be something like:


"adminusers"=>"Home@getUser"

And you would access it using a url like:

http://localhost/myapp/adminusers

In case each user on your system has a unique id and you would like to load different pages for editing or viewing mode, pass all these parameters in the url and give them names with which to access them in this manner:


"adminusers"=>"Home@getUser/id/mode"

Here is an example url you would use to access it:

http://localhost/myapp/adminusers/49723/edit

If you define named url parameters in routes file for a particular route, any additional parameters passed along with the url would be discarded and only the named values would to available.

If you don't name your url parameters, you can access unlimited number of url parameters in the order in which they appear in the url by using indexes begining from 0...onwards.

In case you want to define a route for a controller that is within a subdirectory, e.g:

application/controllers/Admin/HomeController

Specify the namespace in this manner as:


"adminusers"=>"Admin\Home@getUser/id/mode

Requests

Process

A request in Gliver is invoked by accessing a url, for example:

http://localhost/myapp

For the security of your application, excecutable PHP code does not reside in the root of the application.

According to the rules in the .htaccess file in the root directory, all url requests are re-routed into the public directory.

The second .htaccess file in the public directory would check for the nature of this request. If this is a request for an asset file i.e. a css, js, img files it would return the resource. If not, it would direct this request to the index.php file.

It means it's a requests to load a controller class. The controller is the entry point into your application.

This invokes the routing class which checks and disarms the request url against XXS(Cross Site Scripting), as a security measure, before going ahead to parse the request into a controller/method pair.

Request Methods

Gliver url requests are parsed as either a GET or POST request.

You can also pass URL parameters along with the request. These parameters as access are variables through the Input helper class in your controllers.

Check the Input class documentation for more methods that are available to this helper class.

For instance, say you submit a form with a form field name 'email', this is how to access the value of the email parameter using the Input class:


Input::get('email') 

If you define an 'adminusers' in your routes.php file as:


'adminusers' => 'Home@getUser/id/mode' 

Then you access your application through this url:

http://localhost/myapp/adminusers/4957450723/edit

This is how you would access these variables in your application using the Input class.


echo Input::get('id'); //should output 4957450723
echo Input::get('mode'); //should output 'edit'

Because Gliver framework can detect both GET or POST request methods, you can load different controller methods based on your request method.

This means that you can use the same method name but each would be executed at different times depending on the request method

For example:

Say you have a LoginController class and you would like to use the same method name for loading a login form as well as for processing user login information, you will do this as below.

Create two methods named getLogin() and postLogin().


public function getLogin(){
  #...load user login form
}

public function postLogin(){
  #...authenticate email/password pair
}

You will access both methods with this url:

http://localhost/myapp/login/login

Accessing this url in your address bar will load the user login form as the request method is GET and the getLogin method is excecuted.

Once the user fills in the form and submits, Gliver detects this as a POST request and the postLogin method is executed instead.

So, there you go... executing different methods based on the url request method.

Responses

After processing a url request, you respond to the user with the outcome of the request.

All responses are handled with the View helper class.

Check out the View class documentation for more methods that are available to this class.

Upgrade Guide

Previous Versions