[英]how to get value of input in view to controller in codeigniter
I am quite new to CodeIgniter. 我对CodeIgniter很陌生。 In my application I have page where user enters his details. 在我的应用程序中,我有一个页面,用户可以在其中输入他的详细信息。 I want to get that detail in a variable (Lets say just Name ) and want to use that variable in one of the controller file. 我想在一个变量中获取详细信息(比如说Name),并希望在控制器文件之一中使用该变量。
How to do that ? 怎么做 ?
From http://ellislab.com/codeigniter/user-guide/libraries/input.html : 从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
You can also get them by variable name like: 您还可以通过变量名称获取它们,例如:
$somedata = $this->input->post('some_data');
Make sure your form action is pointing to your controller as well. 确保您的表单操作也指向您的控制器。 :) :)
for a form value called "supername" 用于名为“ supername”的表单值
to use locally inside a method 在方法内部局部使用
$supername = $this->input->post( 'supername', TRUE ) ;
to use in any method in the class use $this-> 在类中的任何方法中使用$ this->
$this->supername = $this->input->post( 'supername', TRUE ) ;
In your controller 在您的控制器中
$name= $this->input->post('name');
Better start off with some tutorials on Codeigniter. 最好从Codeigniter上的一些教程开始。
CodeIgniter has this Input class wherein simplifies the inputs when they are used in some conditional statements. CodeIgniter具有此Input类,其中在某些条件语句中使用输入时可以简化输入。
To answer your question, on how to fetch the data entered by the user is by: 要回答您的问题,有关如何获取用户输入的数据的方法是:
$name = $this->input->post('name');
Stores the value of name (it is the name of your field in the form) to a variable name $name . 将name的值(它是表单中字段的名称)存储到变量名$ name 。
Do you want to know if the field is empty or not? 您是否想知道该字段是否为空?
try: 尝试:
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 Input class also has XSS Filtering capabilities, it filters input automatically to prevent cross-site scripting attacks. CodeIgniter Input类还具有XSS筛选功能,它会自动筛选输入以防止跨站点脚本攻击。
All you have to do is: 您要做的就是:
Set it to TRUE in your config/config.php 在您的config / config.php中将其设置为TRUE
$config['global_xss_filtering'] = TRUE;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.