diff develop/classes/loader.php @ 6:63e08b98032f

rewrite extraction interface into PHP MVC architecture. (Although js hasn't been rewritten into MVC, it's fitted into the current PHP MVC architecture.) - The root of the new PHP MVC is at 'develop/'. - extraction interface is called "Extractapp" with several action, eg TaggingText, EditWordlist, EditTaglist, ExportTable.
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Thu, 05 Feb 2015 16:07:53 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/develop/classes/loader.php	Thu Feb 05 16:07:53 2015 +0100
@@ -0,0 +1,57 @@
+<?php
+
+class Loader {
+	private $controller;
+	private $action;
+	private $urlvalues;
+	private $postdata = 0;
+
+	//store the URL values on object creation
+	public function __construct($urlvalues, $postdata) {
+		$this->urlvalues = $urlvalues;
+		$this->postdata = $postdata;
+		if ($this->urlvalues['controller'] == "") {
+			$this->controller = "extractapp";
+			// TODO: develope home page for the whole service.
+			// change $this->controller to home after developed extract app.
+			// $this->controller = "home";
+			
+		} else {
+			$this->controller = $this->urlvalues['controller'];
+		}
+
+		if ($this->urlvalues['action'] == "") {
+			$this->action = "taggingtext";
+			// $this->action = "index";
+		} else {
+			$this->action = $this->urlvalues['action'];
+		}
+
+	}
+	
+	//establish the requested controller as an object
+	public function CreateController() {
+		//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);
+		}
+	}
+}
+
+?>
\ No newline at end of file