Skip to content

Instantly share code, notes, and snippets.

@Nikita240
Created October 30, 2014 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nikita240/fc460428155f0fb55401 to your computer and use it in GitHub Desktop.
Save Nikita240/fc460428155f0fb55401 to your computer and use it in GitHub Desktop.
First @param arguments are missing
<?php
/**
* Controller base class
*
* @package Controllers
*/
/**
* Base class for all controllers.
*
* This class is used as the entry point for controllers.
* It also provides methods for other controller classes to
* navigate within the MVC framework.
*/
abstract class Controller
{
/** @var array $get_vars Array of urlencoded GET variables (usually just the $_GET array). */
protected $get_vars;
/** @var string $action The name of the action to be executed. */
protected $action;
/** @var Template $TemplateEngine Object for templating html. */
protected $TemplateEngine;
/**
* Constructor simply initializes the class properties.
*
* @param string $action The name of the action to be executed.
* @param array $get_vars Array of urlencoded GET variables (usually just the $_GET array).
*/
public function __construct($action, $get_vars)
{
$this->action = $action;
$this->get_vars = $get_vars;
}
/**
* Executes the action.
*/
public function executeAction()
{
$this->{$this->action}();
}
/**
* "Requires" the model.
*
* @param string $model_loc Model location
*/
protected function requireModel($model_loc)
{
require "../app/models/" . $model_loc . ".php";
}
/**
* Gets the path to the view of the current action and initialize the template engine.
*
* The view must be located using this structure:
* ../app/views/controller/action
*
* @return string index.php relative path to the view.
*/
protected function includeView()
{
//start template engine
$this->requireModel("Template");
$this->TemplateEngine = new Template;
//calculate and return the view path
return '../app/views/' . get_class($this) . '/' . $this->action . '.php';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment