Mercurial > hg > extraction-interface
comparison classes/basecontroller.php @ 114:7d6a107c37da extractapp
refactoring, make it more condensed.
| author | Calvin Yeh <cyeh@mpiwg-berlin.mpg.de> |
|---|---|
| date | Thu, 28 Sep 2017 14:01:59 +0200 |
| parents | f1f849d31272 |
| children |
comparison
equal
deleted
inserted
replaced
| 113:e26945b2aa85 | 114:7d6a107c37da |
|---|---|
| 14 * | 14 * |
| 15 * You should have received a copy of the GNU General Public License | 15 * You should have received a copy of the GNU General Public License |
| 16 * along with Extraction-interface. If not, see <http://www.gnu.org/licenses/>. | 16 * along with Extraction-interface. If not, see <http://www.gnu.org/licenses/>. |
| 17 */ | 17 */ |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * A controller can send commands to the model to process or update the model's state. | 20 * A controller can send commands to the model to process or update the model's state. |
| 21 * It can also pass the commands or data (from model) to the associated view to change the view's presentation. | 21 * It can also pass the commands or data (from model) to the associated view to change the view's presentation. |
| 22 * | 22 * |
| 23 * An instance of the BaseController class can't be created directly. | 23 * An instance of the BaseController class can't be created directly. |
| 24 * It can only be extended/inherited by other classes. | 24 * It can only be extended/inherited by other classes. |
| 25 * For example in controllers/ folder, Extractapp is extended from the BaseController. | 25 * For example in controllers/ folder, Extractapp is extended from the BaseController. |
| 26 * An instance of Extractapp can be created directly. | 26 * An instance of Extractapp can be created directly. |
| 27 * | 27 * |
| 28 */ | 28 */ |
| 29 | 29 |
| 30 abstract class BaseController { | 30 abstract class BaseController { |
| 31 | 31 |
| 32 protected $urlvalues; | 32 protected $urlvalues; |
| 33 protected $action; | 33 protected $action; |
| 34 | 34 |
| 35 public function __construct($action, $urlvalues, $postdata) { | 35 public function __construct($action, $urlvalues, $postdata) { |
| 36 $this->action = $action; | 36 $this->action = $action; |
| 37 $this->urlvalues = $urlvalues; | 37 $this->urlvalues = $urlvalues; |
| 38 $this->postdata = $postdata; | 38 $this->postdata = $postdata; |
| 39 } | 39 } |
| 40 | 40 |
| 41 public function ExecuteAction() { | 41 public function ExecuteAction() { |
| 42 return $this->{$this->action}(); | 42 return $this->{$this->action}(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 protected function ReturnView($viewmodel, $fullview) { | 45 protected function ReturnView($viewmodel, $fullview) { |
| 46 /** | 46 /** |
| 47 * Return the corresponding view in the views folder. | 47 * Return the corresponding view in the views folder. |
| 48 * We use the same class name as the folder's name and action name as the file's name in the folder hierarchy. | 48 * We use the same class name as the folder's name and action name as the file's name in the folder hierarchy. |
| 49 * In this design, we can query the corresponding views php code by defining controller and action in url. | 49 * In this design, we can query the corresponding views php code by defining controller and action in url. |
| 50 * | 50 * |
| 51 * If you also require the maintemplate.php, which now only contains scripts that need to be inclued, set $fullview to be true; | 51 * If you also require the maintemplate.php, which now only contains scripts that need to be inclued, set $fullview to be true; |
| 52 * otherwise, the maintemplate.php will not be applied. | 52 * otherwise, the maintemplate.php will not be applied. |
| 53 */ | 53 */ |
| 54 | 54 |
| 55 $viewloc = 'views/' . get_class($this) . '/' . $this->action . '.php'; | 55 $viewloc = 'views/' . get_class($this) . '/' . $this->action . '.php'; |
| 56 if ($fullview) { | 56 if ($fullview) { |
| 57 require('views/maintemplate.php'); | 57 //require('views/maintemplate.php'); |
| 58 require($viewloc); | |
| 59 } else { | |
| 60 require($viewloc); | |
| 61 } | 58 } |
| 59 | |
| 60 require($viewloc); | |
| 62 } | 61 } |
| 63 | 62 |
| 64 protected function ReturnView_localtest($viewmodel, $fullview) { | 63 protected function ReturnView_localtest($viewmodel, $fullview) { |
| 65 /** Return the corresponding view in the views folder. | 64 /** Return the corresponding view in the views folder. |
| 66 * | 65 * |
| 67 * This is only been used when developing on local machine. | 66 * This is only been used when developing on local machine. |
| 68 */ | 67 */ |
| 69 $viewloc = 'views/' . get_class($this) . '/' . $this->action . '.php'; | 68 $viewloc = 'views/' . get_class($this) . '/' . $this->action . '.php'; |
| 70 if ($fullview) { | 69 if ($fullview) { |
| 71 require('views/maintemplate_local.php'); | 70 //require('views/maintemplate_local.php'); |
| 72 require($viewloc); | |
| 73 } else { | |
| 74 require($viewloc); | |
| 75 } | 71 } |
| 72 | |
| 73 require($viewloc); | |
| 76 } | 74 } |
| 77 } | 75 } |
| 78 ?> | 76 ?> |
