view classes/basecontroller.php @ 120:71b611a676c3 extractapp

include maintemplate.php
author Calvin Yeh <cyeh@mpiwg-berlin.mpg.de>
date Thu, 28 Sep 2017 17:48:35 +0200
parents 7d6a107c37da
children
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);
	}

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