我是第一次在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。
3条答案
按热度按时间t3irkdon1#
确保在类中扩展了CI_Controller类
nvbavucw2#
检查POST的Rest配置是否激活?
n3schb8v3#
在函数“cource_topics_post”中传递参数,然后更正此$this-〉post('username');到$this-〉输入-〉post('用户名');