Mercurial > hg > extraction-interface
view classes/loader.php @ 78:960ba96efce1 extractapp
Update: click to popup remove-tag-window; select to popup tag-window
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Mon, 20 Apr 2015 15:44:54 +0200 |
parents | 97c1e5102a22 |
children | f1f849d31272 |
line wrap: on
line source
<?php /** * Loader is used to route parameters from input url and set parameters for controller. * The routing is done by the RewriteRule written in .htaccess file. */ class Loader { private $controller; private $action; private $urlvalues; private $postdata = 0; public function __construct($urlvalues, $postdata) { /** * It stores the URL values on object creation. * For example, the URL structure is like this: some_domain_name/Extractapp/TaggingText. * The controller is "Extractapp" and the action is "TaggingText". * For the "Extractapp" controller, there is a corresponding "extractapp.php" in "./controllers" folder. * For the action "TaggingText", there is a corresponding "TaggingText.php" in "./views/Extractapp" folder. * Under "./view" folder, the first level is named by the controller. Each action belongs to the controller is named by its action name. */ $this->urlvalues = $urlvalues; $this->postdata = $postdata; if ($this->urlvalues['controller'] == "") { $this->controller = "Extractapp"; // the default controller } else { $this->controller = $this->urlvalues['controller']; } if ($this->urlvalues['action'] == "") { $this->action = "TaggingText"; // the default action } else { $this->action = $this->urlvalues['action']; } } public function CreateController() { /** * Establish the requested controller as an object, and check if the query is valid. * The queried controller, which should be extended from BaseController, exists and the queried action should be one of its method. */ //does the class exist? if (class_exists($this->controller)) { $parents = class_parents($this->controller); //does the class extend the controller class? if (in_array("BaseController",$parents)) { //does the class contain the requested method? if (method_exists($this->controller,$this->action)) { return new $this->controller($this->action,$this->urlvalues,$this->postdata); } else { //bad method error return new Error("badUrl",$this->urlvalues); } } else { //bad controller error return new Error("badUrl",$this->urlvalues); } } else { //bad controller error return new Error("badUrl",$this->urlvalues); } } } ?>