当前位置: 首页>>代码示例>>PHP>>正文


PHP ArrayHelper::keyExists方法代码示例

本文整理汇总了PHP中ArrayHelper::keyExists方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper::keyExists方法的具体用法?PHP ArrayHelper::keyExists怎么用?PHP ArrayHelper::keyExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ArrayHelper的用法示例。


在下文中一共展示了ArrayHelper::keyExists方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: prepareDataProvider

 public function prepareDataProvider()
 {
     $params = \Yii::$app->request->queryParams;
     //print_r($params);die();
     $model = new $this->modelClass();
     // I'm using yii\base\Model::getAttributes() here
     // In a real app I'd rather properly assign
     // $model->scenario then use $model->safeAttributes() instead
     $modelAttr = $model->attributes;
     // this will hold filtering attrs pairs ( 'name' => 'value' )
     $search = [];
     if (!empty($params)) {
         foreach ($params as $key => $value) {
             // In case if you don't want to allow wired requests
             // holding 'objects', 'arrays' or 'resources'
             if (!is_scalar($key) or !is_scalar($value)) {
                 throw new BadRequestHttpException('Bad Request');
             }
             // if the attr name is not a reserved Keyword like 'q' or 'sort' and
             // is matching one of models attributes then we need it to filter results
             if (!in_array(strtolower($key), $this->reservedParams) && ArrayHelper::keyExists($key, $modelAttr, false)) {
                 $search[$key] = $value;
             }
         }
     }
     // you may implement and return your 'ActiveDataProvider' instance here.
     // in my case I prefer using the built in Search Class generated by Gii which is already
     // performing validation and using 'like' whenever the attr is expecting a 'string' value.
     $searchByAttr['ProductSearch'] = $search;
     $lat = isset($params['lat']) ? $params['lat'] : 18.509111;
     $lon = isset($params['lon']) ? $params['lon'] : -69.8468487;
     $model = new Categorias();
     $searchModel = $model->find()->all();
     return $searchModel;
 }
开发者ID:alejandrososa,项目名称:AB,代码行数:35,代码来源:CategoriaController.php


注:本文中的ArrayHelper::keyExists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。