简体   繁体   English

如何使用FuelPHP框架获取参数POST或GET并显示在控制器中

[英]how to get parameter POST or GET and showing in controller with FuelPHP framework

i'm having problem when i want to get Parameter value from method POST or GET in FuelPHP framework my question 我想从FuelPHP框架中的POST或GET方法获取参数值时遇到问题

1) that is same with $_GET['params'] or $_POST['params'] ? 1)与$_GET['params']$_POST['params']吗? if same i think i will do something to secure that, i hope any automatically function to secure post and get parameter from fuelphp framework , any someone is know? 如果相同的话,我想我会做些确保这一点的事情,我希望任何自动运行的功能来保护post和从fuelphp框架获取参数,有人知道吗?

2) how i can show that parameter in controller? 2)我如何在控制器中显示该参数? i just try using like this 我只是尝试这样使用

       /*
        * for getting request param for client and save to database
        */
       public function action_input(){
        echo Input::post('name');                                                                                                                                                 
        }

but i'm get error like this 但我得到这样的错误

Fuel\Core\FuelException [ Error ]: The controller action called or it's after() method must return a Response object.

how i can fix that ? 我该如何解决?

thanks you for your helping. 谢谢您的帮助。

http://docs.fuelphp.com/classes/input.html http://docs.fuelphp.com/classes/input.html

<?php echo Input::post('foo') ?>

where "foo" is your POSTed parameter. 其中“ foo”是您的POSTed参数。

Either use a "View" (as suggested above in the comments) to display your response or do the following in your controller action. 使用“视图”(如上面的注释中所建议)来显示您的响应,或者在控制器操作中执行以下操作。

return new Response(Input::post(<your_parameter_here>));

The primary reason is as quoted in the documentation. 主要原因是在文档中引用的。
http://docs.fuelphp.com/general/controllers/base.html http://docs.fuelphp.com/general/controllers/base.html

"A controller action MUST return a Response object. Optionally you can specify special HTTP headers, or a custom HTTP status code (a code other than "200 OK"). “控制器动作必须返回一个Response对象。您可以选择指定特殊的HTTP标头或自定义的HTTP状态代码(“ 200 OK”以外的代码)。

If your controller extends one of the base controllers, your action can also return any value that can be cast to string, like for example a View object. 如果您的控制器扩展了基本控制器之一,则您的操作还可以返回可以转换为字符串的任何值,例如View对象。 The after() method of the base controller will convert it into a Response object for you. 基本控制器的after()方法将为您将其转换为Response对象。

If your controller does not extend one of the base controllers, and you want to use this feature, your controller must contain it's own after() method that will accept the actions return value, and has to wrap it into a Reponse object which it must return. 如果您的控制器没有扩展基本控制器之一,并且您想使用此功能,则您的控制器必须包含其自己的after()方法,该方法将接受操作返回值,并且必须将其包装到必须包含的Reponse对象中返回。 "

请看看fuelPHP中的POST方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM