Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 获取codeigniter中的post in控制器的值_Php_Codeigniter_Post - Fatal编程技术网

Php 获取codeigniter中的post in控制器的值

Php 获取codeigniter中的post in控制器的值,php,codeigniter,post,Php,Codeigniter,Post,我想在视图中放置两个按钮。两个按钮将值发送到一个控制器。 如何检查按下哪个按钮?! 根据这个链接 但在控制器中无法获取按钮的值。有什么想法吗?使用相同的方法,但是在CodeIgniter中,您的代码看起来会更清晰一些: <form action="TheController/PostHandler" method="POST"> <input type="submit" name="button1" id="button1" value="Button 1" />

我想在视图中放置两个按钮。两个按钮将值发送到一个控制器。 如何检查按下哪个按钮?! 根据这个链接


但在控制器中无法获取按钮的值。有什么想法吗?

使用相同的方法,但是在CodeIgniter中,您的代码看起来会更清晰一些:

<form action="TheController/PostHandler" method="POST">
    <input type="submit" name="button1" id="button1" value="Button 1" />
    <input type="submit" name="button2"  id="button2" value="Button 2" />
</form>
相当于:

$something = isset($_POST['something']) ? $_POST['something'] : NULL;
只需使用如下代码检查空值:

public function PostHandler(){
    if (!is_null($this->input->post('button1'))){
        // code for button 1
    }

    if (!is_null($this->input->post('button2'))){
        // code for button 2
    }
}

使用相同的方法,但是在CodeIgniter中,您的代码看起来更清晰:

<form action="TheController/PostHandler" method="POST">
    <input type="submit" name="button1" id="button1" value="Button 1" />
    <input type="submit" name="button2"  id="button2" value="Button 2" />
</form>
相当于:

$something = isset($_POST['something']) ? $_POST['something'] : NULL;
只需使用如下代码检查空值:

public function PostHandler(){
    if (!is_null($this->input->post('button1'))){
        // code for button 1
    }

    if (!is_null($this->input->post('button2'))){
        // code for button 2
    }
}
使用

使用


我只写了这个代码“如果(!is_null($this->input->post('button1')){}”。但是我按了按钮2,这就行了。我真的搞糊涂了。我觉得表单助手更好是的,我在按钮2的名称下有一个类型,刚刚修复了它。我只放了这个代码“if(!is_null($this->input->post('button1')){}”。但我按了按钮2,这就行了。我真的搞糊涂了。对不起,我觉得表单助手更好。是的,我在按钮2的名称下有一个类型,只是修复了它不是专家,但是如果你想确定哪个按钮被按下,那么你可以给出该按钮名称并在输入帖子数组中获取该名称。不是专家,但是如果你想确定哪个按钮被按下,那么你可以给出该按钮名称并在输入帖子数组中获取该名称。