Controllers - ace411/Bingo-Framework GitHub Wiki

#Controllers

All the controller files in the App directory extend the base controller and allow the framework to achieve an inversion of control. The controllers defined in Bingo make it possible to combine data accessed via models and front-end elements used in the views thereby completing the Model View Controller sequence.

##Creating controllers

###Bingo URL anatomy

The URL's in Bingo look like this $PROTOCOL://$DOMAIN:$PORT/$PATH . Controller classes and their respective methods are part of the URL path; path elements are read as Controller files from which the appropriate views are rendered.

###Controllers in the App directory

Controller classes are typed in StudlyCaps and the methods are typed in camelCase. Also, the controller method names are proceeded with the word Action because of the action filter system used in the base controller class. Consider the example declaration used below:

namespace App\Controllers;

use App\Models\Home;
use \Core\Views;

class Home extends \Core\Controller
{
        public function indexAction()
	{
		$view = new Views();
                $home = new Home(); //Home is a model which contains database information 
                $data = $home->getMessages(); //get messages is defined in the model Home
		$values = [
			'title' => 'Articles | Bingo Framework',
			'stylesheet' => Views::returnURL(true, 'style') . 'main.css',
			'font' => Views::returnURL(true, 'font') . 'Ubuntu.css',
			'firstname' => 'Bingo',
                        'data' => $data
		];
		echo $view->mustacheRender('base', $values); //render the template base.html in the Mustache directory
	}
}

The data from the Home model and other arbitrary front-end information is parsed through the controller created above; it can be accessed via the URL with the structure $PROTOCOL:$DOMAIN:$PORT/home/index.