简体   繁体   English

如何在Codeigniter的控制器中获取输入值

[英]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.

相关问题 CodeIgniter:如何从View获取输入并在控制器中使用它 - CodeIgniter: How to get input from View and use it in the controller 如何从视图到控制器Codeigniter获取自动完成值 - How to get autocomplete value from view to controller Codeigniter CodeIgniter - 如何将值从视图传递到控制器? - CodeIgniter - How to pass a value from a view to a controller? 如何将输入值从视图传递到控制器和模型以正确获取数据? 代码点火器 - How can I pass input value from view to controller and model to fetch data correctly? Codeigniter 如何在Codeigniter控制器中获取参数值? - how to get parameter value in codeigniter controller? 如何从视图到控制器方法获取变量值,然后将这些值传递给模态以存储在数据库中:codeigniter - How to get variables values from a view to controller method and then pass these value to a modal to store in database:codeigniter 控制器未在Codeigniter中获取输入值 - Controller is not getting input value in codeigniter 如何从Controller获取数据以在Codeigniter中查看并在视图上打印 - How to get data from Controller to view in codeigniter and print on view 如何在Codeigniter中获取输入表单的JSON值 - How to get json value of input form in codeigniter 如何在Codeigniter中获取表单输入框的值 - how to get the value of form input box in codeigniter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM