【问题标题】:get value of post in controller in codeigniter在codeigniter中获取控制器中post的值
【发布时间】:2017-01-26 19:18:31
【问题描述】:

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

但在控制器中没有得到按钮的值。有什么想法吗?

【问题讨论】:

  • 不是专家,但如果您想确定按下的是哪个按钮,那么您可以给出该按钮名称并在输入后数组中获取该名称。

标签: php codeigniter post


【解决方案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>

因为在 CodeIgniter 中,这是:

$something = $this->input->post('something');

相当于:

$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
    }
}

【讨论】:

【解决方案2】:
$this->input->post('some_data'); // The function returns FALSE (boolean) if some_data not isset

使用

if($this->input->post('button1')){
$button1 = $this->input->post('some_data',true) //for xss
} else { $bouton1 = false;} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-25
    • 2012-12-08
    • 1970-01-01
    • 2015-12-10
    • 1970-01-01
    相关资源
    最近更新 更多