2

我正在使用 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 调用的更好方法。

4

0 回答 0