如何在编码器中获取视图输入值到控制器


how to get value of input in view to controller in codeigniter

我是CodeIgniter的新手。在我的应用程序中,我有用户输入他的详细信息的页面。我想在变量中获取细节(比如Name),并希望在一个控制器文件中使用该变量。

怎么做?

对于名为"supername"的表单值

在方法内部局部使用

$supername = $this->input->post( 'supername', TRUE ) ;
使用$this->
$this->supername = $this->input->post( 'supername', TRUE ) ;

在你的控制器

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

最好从Codeigniter的一些教程开始。

From http://ellislab.com/codeigniter/user-guide/libraries/input.html:

$post = $this->input->post();
//on the controller you can access this and will return the array
//of the post data you submitted

您也可以通过变量名获取它们,例如:

$somedata = $this->input->post('some_data');

确保你的表单动作也指向你的控制器。:)

CodeIgniter有这个Input类,其中简化了在某些条件语句中使用的输入。

关于如何获取用户输入的数据的问题:

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

name的值存储到一个变量名$name

您想知道字段是否为空吗?

试题:

if($name = $this->input->post('name')){
    //$name has the value of the name field and it is not empty, do something.
}else{
    //$name has the value of the name field and it is empty, do something.
}

CodeIgniter输入类还具有XSS过滤功能,它自动过滤输入以防止跨站脚本攻击。

你所要做的就是:

在config/config.php中设置为TRUE

$config['global_xss_filtering'] = TRUE;