public function actionIndex($search) { if ($search != null && $search != '') { $search = htmlspecialchars($search, ENT_HTML5); $activitySearchModel = new ActivitySearchGlobal(); $activitySearchModel->globalSearch = $search; $activitySearchModelDataProvider = $activitySearchModel->search(Yii::$app->request->queryParams); $outdoorAttractionSearchModel = new OutsideAttractionSearchGlobal(); $outdoorAttractionSearchModel->globalSearch = $search; $outdoorAttractionDataProvider = $outdoorAttractionSearchModel->search(Yii::$app->request->queryParams); $dataProvider = BaseArrayHelper::merge($activitySearchModelDataProvider, $outdoorAttractionDataProvider); if (Yii::$app->user->can('postIndex')) { $postSearchModel = new PostSearchGlobal(); $postSearchModel->globalSearch = $search; $postDataProvider = $postSearchModel->search(Yii::$app->request->queryParams); $dataProvider = BaseArrayHelper::merge($dataProvider, $postDataProvider); $postReplySearchModel = new PostReplaySearchGlobal(); $postReplySearchModel->globalSearch = $search; $postReplyDataProvider = $postReplySearchModel->search(Yii::$app->request->queryParams); $dataProvider = BaseArrayHelper::merge($dataProvider, $postReplyDataProvider); } if (Yii::$app->user->can('announcementIndex')) { $announcementSearchModel = new AnnouncementSearchGlobal(); $announcementSearchModel->globalSearch = $search; $announcementDataProvider = $announcementSearchModel->search(Yii::$app->request->queryParams); $dataProvider = BaseArrayHelper::merge($dataProvider, $announcementDataProvider); } return $this->render('index', ['input' => $search, 'result' => $dataProvider]); } else { throw new ForbiddenHttpException(Yii::t('yii', 'Input something')); } }
public static function getList() { $data = self::find()->all(); if ($data === null) { throw new HttpException(404, "Ошибка"); } return \yii\helpers\BaseArrayHelper::map($data, 'id', 'name'); }
/** * @return array */ public function getDataOptions() { if ($this->data) { return $this->data; } $modelClass = $this->getTargetModelClass(); $options = BaseArrayHelper::map($modelClass::find()->all(), $this->getTargetPrimaryKey(), $this->titleAttr); return $options; }
/** * @param $users_info * @param $name * @return array */ public function getUsersInfo($users_info, $name) { $array = []; //get needed column $users_info = array_filter(BaseArrayHelper::getColumn($users_info, $name, false)); $users_info = array_count_values($users_info); foreach ($users_info as $key => $value) { $array[] = [$key, $value]; } return $array; }
public function beforeAction($event) { $this->requestAction = $event->action; $this->requestHeaders = \Yii::$app->request->getHeaders(); $this->requestData = BaseArrayHelper::merge(\Yii::$app->request->getBodyParams(), \Yii::$app->request->get()); $this->requestMethod = \Yii::$app->request->getMethod(); if ($this->requestMethod === 'OPTIONS') { return; } $this->checkAction(); $this->checkMethod(); $this->checkRequestStructure(); $this->checkHeaders(); return true; }
private function getImagesFinder($additionWhere = false) { $base = ['itemId' => $this->owner->id, 'modelName' => $this->getModule()->getShortClass($this->owner)]; if ($additionWhere) { $base = \yii\helpers\BaseArrayHelper::merge($base, $additionWhere); } return $base; }
/** * @param string|array $paramValue ['email' => 'name'] or 'email' * @param string $paramType sendGrid var name like cc, bcc, to */ private function addSingleParam($paramValue, $paramType) { $addFunction = 'add' . ucfirst($paramType); if (is_array($paramValue) && BaseArrayHelper::isAssociative($paramValue)) { $this->sendGridMessage->{$addFunction}(key($paramValue), current($paramValue)); } else { $this->sendGridMessage->{$addFunction}($paramValue); } }
<?php /** * Hello world! */ if (isset($_SERVER['YII_ENV']) && $_SERVER['YII_ENV'] === 'DEV') { defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'dev'); } require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php'; require __DIR__ . '/../config/bootstrap.php'; // Merge global and local configs $config = (require __DIR__ . '/../config/web.php'); $localConfigPath = __DIR__ . '/../config/local/web.php'; if (file_exists($localConfigPath)) { $localConfig = (require $localConfigPath); $config = \yii\helpers\BaseArrayHelper::merge($config, $localConfig); } // Classes configuration (via Dependency Injection) // http://www.yiiframework.com/doc-2.0/guide-concept-di-container.html require __DIR__ . '/../config/di.php'; (new yii\web\Application($config))->run();
/** * @param string|null $to * @param string|null $subject * @param string|null $view * @param string|null $sender * @param array $params{'user', 'reply_to', 'body', 'header', 'mandrill_template_name', 'tags', 'vars', 'from_name'} */ function __construct($to = null, $subject = null, $view = null, $sender = null, $params = []) { $this->to = $to; $this->subject = $subject; $this->view = $view; $this->params = $params; $c1 = $c2 = $c3 = $c4 = $cfg = []; if (file_exists(\Yii::getAlias('@app') . '/../common/config/' . '/main-local.php')) { $c1 = (require \Yii::getAlias('@app') . '/../common/config/' . '/main-local.php'); } if (file_exists(\Yii::getAlias('@app') . '/../common/config/' . '/main.php')) { $c2 = (require \Yii::getAlias('@app') . '/../common/config/' . '/main.php'); } if (file_exists(\Yii::getAlias('@app') . '/../frontend/config/' . '/main.php')) { $c3 = (require \Yii::getAlias('@app') . '/../frontend/config/' . '/main.php'); } if (file_exists(\Yii::getAlias('@app') . '/../frontend/config/' . '/main-local.php')) { $c4 = (require \Yii::getAlias('@app') . '/../frontend/config/' . '/main-local.php'); } $cfg = \Yii\helpers\BaseArrayHelper::merge($c1, $c2); $cfg = \Yii\helpers\BaseArrayHelper::merge($cfg, $c3); $cfg = \Yii\helpers\BaseArrayHelper::merge($cfg, $c4); if (isset($cfg['components']['mailer'])) { $mailer_config = $cfg['components']['mailer']; } if (isset($cfg['components']['mailer']['apikey'])) { $this->apikey = $cfg['components']['mailer']['apikey']; } if (isset($mailer_config['viewPath'])) { $this->viewPath = $mailer_config['viewPath']; } if ($this->sender === null) { $this->sender = isset(\Yii::$app->params['adminEmail']) ? \Yii::$app->params['adminEmail'] : '*****@*****.**'; } if ($this->replyTo === null) { $this->replyTo = isset($this->params['reply_to']) ? $this->params['reply_to'] : '*****@*****.**'; } if ($this->body === null) { $this->body = isset($this->params['body']) ? $this->params['body'] : null; } if ($this->header === null) { $this->header = isset($this->params['header']) ? $this->params['header'] : null; } if ($this->mandrill_template_name === null) { $this->mandrill_template_name = isset($this->params['mandrill_template_name']) ? $this->params['mandrill_template_name'] : null; } if ($this->tags === null) { $this->tags = isset($this->params['tags']) ? $this->params['tags'] : ['razzd']; } if ($this->vars === null) { $this->vars = isset($this->params['vars']) ? $this->params['vars'] : null; } if ($this->fromName === null) { $this->fromName = isset($this->params['from_name']) ? $this->params['from_name'] : 'Your friendly manager'; } }
public function init() { $this->assignRule(); $this->rules = BaseArrayHelper::merge($this->mainRules, $this->rules); return parent::init(); }