나는 일부 jsons를 반환하거나 저장하기 위해 PHP 함수를 만들었고 클래스는 다음과 같이 보입니다. 무엇 궁금문자열에서 php 함수 이름을 호출합니다.
<?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();
?>
, 내가 어떻게 든/다른 기능이 executeAction
라고하면 경우 대신 그 큰 수 있도록 문자열 이름에서 contruct에서 작업을 호출 할 수 있습니다. 미리 감사드립니다, 대니얼!
'call_user_func은 ()' – zerkms
@zerkms'$ this'는 일을 복잡하게 만듭니다. – kapa
@kapa :'call_user_func (array ($ this, 'methodname'))' – zerkms