-
-
Save Nikita240/fc460428155f0fb55401 to your computer and use it in GitHub Desktop.
First @param arguments are missing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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