if (empty($this->dsn)) { throw new InvalidConfigException($this->className() . '::dsn cannot be empty.'); } $token = 'Opening MongoDB connection: ' . $this->dsn; try { Yii::trace($token, __METHOD__); Yii::beginProfile($token, __METHOD__); $options = $this->options; $this->manager = new Manager($this->dsn, $options, $this->driverOptions); $this->manager->selectServer($this->manager->getReadPreference()); $this->initConnection(); Yii::endProfile($token, __METHOD__); } catch (\Exception $e) { Yii::endProfile($token, __METHOD__); throw new Exception($e->getMessage(), (int) $e->getCode(), $e); }
$token = $this->log([$databaseName, 'command'], $this->document, __METHOD__); try { $this->beginProfile($token, __METHOD__); $this->db->open(); $mongoCommand = new \MongoDB\Driver\Command($this->document); $cursor = $this->db->manager->executeCommand($databaseName, $mongoCommand, $this->getReadPreference()); $cursor->setTypeMap($this->db->typeMap); $this->endProfile($token, __METHOD__); } catch (RuntimeException $e) {
* @param array $options list of options in format: optionName => optionValue. * @return array array of distinct values, or "false" on failure. */ public function distinct($collectionName, $fieldName, $condition = [], $options = []) { $this->document = $this->db->getQueryBuilder()->distinct($collectionName, $fieldName, $condition, $options); $cursor = $this->execute(); $result = current($cursor->toArray()); if (!isset($result['values']) || !is_array($result['values'])) { return false; }
* @param array $options list of options in format: optionName => optionValue. * @return array|bool array of distinct values, or "false" on failure. * @throws Exception on failure. */ public function distinct($column, $condition = [], $options = []) { return $this->database->createCommand()->distinct($this->name, $column, $condition, $options); } /** * Performs aggregation using Mongo Aggregation Framework. * In case 'cursor' option is specified [[\MongoDB\Driver\Cursor]] instance is returned, * otherwise - an array of aggregation results.
$collection = $this->getCollection($db); if ($this->where !== null) { $condition = $this->where; } else { $condition = []; } $result = $collection->distinct($q, $condition); if ($result === false) { return []; } return $result; }
*/ public function actionSearch() { $where = []; $spe = Specifications::find()->distinct('type'); foreach($spe as $s){ if(isset($_GET[$s]) && !empty($_GET[$s])){ $where[$s] = intval($_GET[$s]); } } $searchModel = new ProductSearch();
$args = $this->controller->bindActionParams($this, $params); Yii::debug('Running action: ' . get_class($this->controller) . '::' . $this->actionMethod . '()', __METHOD__); if (Yii::$app->requestedParams === null) { Yii::$app->requestedParams = $args; } return call_user_func_array([$this->controller, $this->actionMethod], $args); } }
} $result = null; if ($runAction && $this->beforeAction($action)) { // run the action $result = $action->runWithParams($params); $result = $this->afterAction($action, $result); // call afterAction on modules foreach ($modules as $module) { /* @var $module Module */
$parts = $this->createController($route); if (is_array($parts)) { /* @var $controller Controller */ list($controller, $actionID) = $parts; $oldController = Yii::$app->controller; Yii::$app->controller = $controller; $result = $controller->runAction($actionID, $params); if ($oldController !== null) { Yii::$app->controller = $oldController; } return $result; }
$params = $this->catchAll; unset($params[0]); } try { Yii::debug("Route requested: '$route'", __METHOD__); $this->requestedRoute = $route; $result = $this->runAction($route, $params); if ($result instanceof Response) { return $result; } $response = $this->getResponse(); if ($result !== null) {
{ try { $this->state = self::STATE_BEFORE_REQUEST; $this->trigger(self::EVENT_BEFORE_REQUEST); $this->state = self::STATE_HANDLING_REQUEST; $response = $this->handleRequest($this->getRequest()); $this->state = self::STATE_AFTER_REQUEST; $this->trigger(self::EVENT_AFTER_REQUEST); $this->state = self::STATE_SENDING_RESPONSE; $response->send();
require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php'; $config = require __DIR__ . '/../config/web.php'; (new yii\web\Application($config))->run();
$_GET = [ 'sort' => 'price', 'page' => '4', ];