i created a php function to return or save some jsons, and the class looks like this.
<?php
class calendarModel {
// global variables
var $user;
var $action;
var $connect;
// init class
function __construct($action = "getEvents") {
$this->user = 1;
$this->action = $action;
$dbhost = "localhost";
$dbport = "5432";
$dbname = "fixevents";
$dbuser = "postgres";
$dbpass = "123";
$this->connect = pg_connect("host=" . $dbhost . " port=" . $dbport . " dbname=" . $dbname . " user=" . $dbuser . " password=" . $dbpass);
$this->executeAction();
}
// action router
function executeAction() {
if($this->action == "getEvents")
$this->getEvents();
else if($this->action == "moveEvent")
$this->moveEvent();
else if($this->action == "insertEvent")
$this->insertEvent();
else if($this->action == "updateEvent")
$this->updateEvent();
else if($this->action == "getCalendars")
$this->getCalendars();
else if($this->action == "toggleCalendar")
$this->toggleCalendar();
else if($this->action == "deleteCalendar")
$this->deleteCalendar();
else if($this->action == "insertCalendar")
$this->insertCalendar();
}
// getEvents
function getEvents() {
//...
}
// moveEvent
function moveEvent() {
//...
}
// insertEvent
function insertEvent() {
//...
}
// updateEvent
function updateEvent() {
//...
}
// toggleCalendar
function toggleCalendar() {
//...
}
// deleteCalendar
function deleteCalendar() {
//...
}
// insertCalendar
function insertCalendar() {
//...
}
}
// call class
if(isset($_GET['action']))
$instance = new calendarModel($_GET['action']);
else
$instance = new calendarModel();
?>
What i was wondering is, can i somehow call the action in the contruct from the string name instead make that big if / else if function called executeAction
. Thank you in advance, Daniel!