我在codeigniter中第一次使用REST API。 我在api中有以下功能
public function cource_topics_post() {
$username = $this->input->post('username');
//$value=$this->uri->segment(3);
$this->response(array('status' => 1, 'username' => $username ));
}
但是
$username = $this->input->post('username');
无效。需要帮助
我的控制器如下
<?php
header("Access-Control-Allow-Origin: *");
require(APPPATH . '/libraries/REST_Controller.php');
class Admin extends REST_Controller {
function __construct() {
parent::__construct();
$this->load->helper('file');
$this->load->helper(array('form', 'url'));
}
public function cource_topics_post() {
$username = $this->post('username');
$password = $this->post('password');
//$value=$this->uri->segment(3);
$user = "faizan";
$pass = "faizan";
if($username == $user && $password == $pass){
$this->response(array('status' => 1, 'logged in as' => $username ));
}
else{
$this->response(array('status' => 0, 'Could not login' => 'incorrect username password'));
}
}
}
我正在使用rest_controller。
答案 0 :(得分:0)
确保您在班级
中扩展了 CI_Controller 课程答案 1 :(得分:0)
检查 POST 的Rest配置,是否已激活?