在测试过程中,我检查了我的一个特定功能,它不应该像它应该的那样工作,这是我的代码和配置之前我给你的事实:
.htaccess :( codeIgniter的根目录)
RewriteEngine On
RewriteRule ^(application) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
测试人员控制器:
class Tester extends REST_Controller {
function __construct()
{
// Construct the parent class
parent::__construct();
$this->load->model('Tester_model');
// Configure limits on our controller methods
// Ensure you have created the 'limits' table and enabled 'limits' within application/config/rest.php
$this->methods['user_get']['limit'] = 50000; // 500 requests per hour per user/key
$this->methods['user_post']['limit'] = 10000; // 100 requests per hour per user/key
$this->methods['user_delete']['limit'] = 5000; // 50 requests per hour per user/key
}
public function courseinfo_post(){
$cc = $this->post('courseid'); // test it like coursed = 7
if($cc == ""){
$this->response([
'status' => FALSE,
'value' => $cc
], REST_Controller::HTTP_BAD_REQUEST);
}else{
$this->set_response([ ‘status’ => TRUE ], REST_Controller::HTTP_OK);
}
public function test_post(){
$dd = $this->post('hi'); // test it like hi=7
$this->response([
'value1' => $dd
], REST_Controller::HTTP_OK);
}
}
我给了它几个试验,并了解了以下事实:
参数courseinfo_post()
的函数courseid=7
无法正常工作,而是为什么是null?
为什么相同类型的方法test_post()
与参数hi=7
完全正常。
我注意到如果我在函数courseinfo_post()
中传递了多个参数,它运行正常,为什么会这样?
注意:我正在研究3.0.6
system/core/CodeIgnitor
的codeIgniter
如何使courseinfo_post()
仅使用一个参数?
答案 0 :(得分:1)
请使用正确的语法,即$ this-> input-> post('courseid');
$cc = $this->input->post('courseid'); // test it like coursed = 7
instead of
$cc = $this->post('courseid'); // test it like coursed = 7
或尝试
print_r($this->input->post(null,TRUE));
或在您使用休息时更新您的代码
class my_controller_name extends REST_Controller{
public $requestVar = array( 'courseid'=>'',
);
public function courseinfo_post(){
$response = $this->input->post(NULL, TRUE);
$response = (is_array($response)?array_map("trim", $response):'');
foreach($this->requestVar as $key=>$var){
$this->requestVar[$key] = urldecode((isset($response[$key])?$response[$key]:$this->requestVar[$key]));
}
print_r($this->requestVar); // use it wherever u need
}
}