【问题标题】:how to yii getPost for array _POST vars?如何为数组 _POST vars 获取 getPost?
【发布时间】:2012-08-31 08:46:07
【问题描述】:

假设我有

$_POST["x"]["y"] = 5;

我该怎么做

Yii::app()->request->getPost('x[y]');

如何按索引检索 post 变量? 是否有任何检查 sql 注入的 yii 函数? getPost 会做那个检查吗?

谢谢。

【问题讨论】:

标签: php yii http-post


【解决方案1】:
> My controller 
>     public function mi(){
>         echo "Hola MI Controlador!";
>         // in login scenario
> 
>         $request = Yii::app()->request->getPost('nombre');
>         print_r($request);
> 
> 
>         //$this->render('index',array('nombre',$post));
>     } 

【讨论】:

  • 如果我不使用数据库,必须使用模型发布数据???帖子不工作请帮助我!在控制器的 laravel 中,您可以使用这个公共函数 mi(request){ var_dump($request) };但是在yii中我不明白逻辑!是不同的,在指南上没有很多解决方案感谢您的关注! yii 组
【解决方案2】:

Yii::app()->request->getParam('delete');

你可以看到这个链接

http://www.yiiframework.com/forum/index.php/topic/28547-get-post-parameters-with-the-same-name/

【讨论】:

    【解决方案3】:

    Yii2

    $x = Yii::$app->request->post('x');
    

    【讨论】:

    • $x = Yii::app()->request->post('x'); $y = $x['y'];
    【解决方案4】:

    使用模型测试它看起来像这样

    $test = new Test();
    $test->attributes = Yii::app()->request->getPost('x');   
    $y = $test->getAttribute('y');
    

    【讨论】:

      【解决方案5】:

      我对yii不熟悉,但是在看函数的源码 https://github.com/yiisoft/yii/blob/1.1.12/framework/web/CHttpRequest.php

      你会的

      $x = Yii::app()->request->getPost('x');
      $y = $x['y'];
      

      getPost 函数不会阻止 sql 注入。请阅读http://www.yiiframework.com/wiki/275/how-to-write-secure-yii-applications/#hh11 了解有关保护您的 yii 应用程序的更多信息

      【讨论】:

      • 顺便说一句,如果您需要从 $_GET 数组中获取值,您需要编写 $x = Yii::app()->request->getQuery('x');
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-10
      • 2021-04-08
      • 1970-01-01
      • 2021-11-13
      • 1970-01-01
      • 2021-01-14
      • 2020-02-12
      相关资源
      最近更新 更多