view classes/basecontroller.php @ 81:f1f849d31272 extractapp

book_id as string
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Thu, 23 Apr 2015 14:58:27 +0200
parents 97c1e5102a22
children 7d6a107c37da
line wrap: on
line source

<?php
/* basecontroller.php
 * This file is part of Extraction-interface.
 *
 * Extraction-interface is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Extraction-interface is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Extraction-interface.  If not, see <http://www.gnu.org/licenses/>.
*/

/** 
 * A controller can send commands to the model to process or update the model's state. 
 * It can also pass the commands or data (from model) to the associated view to change the view's presentation.
 * 
 * An instance of the BaseController class can't be created directly.
 * It can only be extended/inherited by other classes. 
 * For example in controllers/ folder, Extractapp is extended from the BaseController. 
 * An instance of Extractapp can be created directly.
 * 
*/

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 query 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);
        }
    }
}
?>