私は codeigniter を使用していくつかの RESTful サービスを開発しています。HTTPリクエスト(GET、POST、DELETE、PUT)に基づいて、子コントローラーでさまざまなメソッドを呼び出すベースコントローラーがあります。以下は、子コントローラーのコードです。
class Example extends REST_Controller
{
private $username;
private $password;
private $time_format;
private $date_format;
private $tz;
private $tz_utc;
private $prefs;
function __construct() {
parent::__construct();
// mod_php
if ($this->input->server('PHP_AUTH_USER'))
{
$this->username = $this->input->server('PHP_AUTH_USER');
$this->password = $this->input->server('PHP_AUTH_PW');
}
// most other servers
elseif ($this->input->server('HTTP_AUTHENTICATION'))
{
if (strpos(strtolower($this->input->server('HTTP_AUTHENTICATION')), 'basic') === 0)
{
list($this->username, $this->password) = explode(':', base64_decode(substr($this->input->server('HTTP_AUTHORIZATION'), 6)));
}
}
// FIXME: Does this case appear ? We are already validating in Parent class
// @see REST_Controller:220,213
if ( $this->username == null || $this->password == null) {
$this->output->set_output(json_encode(' Unauthorized access '));
}
$this->date_format = $this->dates->date_format_string('date');
$this->time_format = $this->dates->time_format_string('date');
$this->tz = $this->timezonemanager->getTz(
$this->config->item('default_timezone'));
$this->tz_utc = $this->timezonemanager->getTz('UTC');
// we are not loading any user preferences
//$this->prefs =
//Preferences::singleton($this->session->userdata('prefs'));
$this->load->library('caldav');
$this->output->set_content_type('application/json');
}
/**
* Fetches all calendars of logged in user
*/
function allcalendar_get()
{
$arr_calendars = $this->caldav->all_user_calendars(
$this->username,
$this->password);
$this->output->set_output(json_encode($arr_calendars));
}
/**
* Creates a calendar
*/
function newcalendar_post()
{
// Get current own calendars
$current_calendars = $this->caldav->get_own_calendars(
$this->username,
$this->password
);
}
// deletes a resource
function event_delete() {
if (!$this->get('href'))
{ // response is 400 eventhough I pass href in url like below
// http://localhost/app/index.php/example/event?href=89290E
$this->response(NULL, 400);
}
}
}
$this->get('href') を使用して event_delete メソッド内の url で渡された href パラメーターにアクセスしようとしていますが、渡された値が空です。パラメータを DELETE REST 呼び出しに渡すより良い方法を提案してください。