view classes/basecontroller.php @ 77:97c1e5102a22 extractapp

New: export table for a file from LGService
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Thu, 16 Apr 2015 14:53:22 +0200
parents 886f43b26ee2
children f1f849d31272
line wrap: on
line source

<?php
/** 
* An instance of the BaseController class can't be created directly.
* It can only be extended/inherited by other classes.
*/

abstract class BaseController {
	
	protected $urlvalues;
	protected $action;
	
	public function __construct($action, $urlvalues, $postdata) {
		$this->action = $action;
		$this->urlvalues = $urlvalues;
		$this->postdata = $postdata;
	}
	
	public function ExecuteAction() {
		return $this->{$this->action}();
	}
	
	protected function ReturnView($viewmodel, $fullview) {
		/** 
		* Return the corresponding view in the views folder. 
		* We use the same class name as the folder's name and action name as the file's name in the folder hierarchy.
		* In this design, we can require the corresponding views php code by defining controller and action in url.
		* 
		* If you also require the maintemplate.php, which now only contains scripts that need to be inclued, set $fullview to be true; 
		* otherwise, the maintemplate.php will not be applied.
		*/

		$viewloc = 'views/' . get_class($this) . '/' . $this->action . '.php';
		if ($fullview) {
			require('views/maintemplate.php');
			require($viewloc);
		} else {
			require($viewloc);
		}
	}

	protected function ReturnView_localtest($viewmodel, $fullview) {
		/** Return the corresponding view in the views folder.  
		* 
		* This is only been used when developing on local machine. 
		*/
        $viewloc = 'views/' . get_class($this) . '/' . $this->action . '.php';
        if ($fullview) {
            require('views/maintemplate_local.php');
            require($viewloc);
        } else {
            require($viewloc);
        }
    }
}
?>