本文整理汇总了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;
}