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) {
* @return int records count */ public function count($collectionName, $condition = [], $options = []) { $this->document = $this->db->getQueryBuilder()->count($collectionName, $condition, $options); $result = current($this->execute()->toArray()); return $result['n']; } /** * Adds the insert operation to the batch command. * @param array $document document to be inserted
* @param array $options list of options in format: optionName => optionValue. * @return int records count. * @since 2.1 */ public function count($condition = [], $options = []) { return $this->database->createCommand()->count($this->name, $condition, $options); } /** * Returns a list of distinct values for the given column across a collection. * @param string $column column to use. * @param array $condition query parameters.
{ if (!empty($this->emulateExecution)) { return 0; } $this->prepare(); $collection = $this->getCollection($db); return $collection->count($this->where, $this->options); } /** * Returns a value indicating whether the query result contains any row of data. * @param Connection $db the Mongo connection used to execute the query. * If this parameter is not given, the `mongodb` application component will be used.
protected function prepareTotalCount() { if (!$this->query instanceof QueryInterface) { throw new InvalidConfigException('The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses.'); } $query = clone $this->query; return (int) $query->limit(-1)->offset(-1)->orderBy([])->count('*', $this->db); } /** * {@inheritdoc} */ public function setSort($value)
*/ public function getTotalCount() { if ($this->getPagination() === false) { return $this->getCount(); } elseif ($this->_totalCount === null) { $this->_totalCount = $this->prepareTotalCount(); } return $this->_totalCount; } /**
{ if (!$this->query instanceof QueryInterface) { throw new InvalidConfigException('The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses.'); } $query = clone $this->query; if (($pagination = $this->getPagination()) !== false) { $pagination->totalCount = $this->getTotalCount(); if ($pagination->totalCount === 0) { return []; } $query->limit($pagination->getLimit())->offset($pagination->getOffset()); } if (($sort = $this->getSort()) !== false) {
* * @param bool $forcePrepare whether to force data preparation even if it has been done before. */ public function prepare($forcePrepare = false) { if ($forcePrepare || $this->_models === null) { $this->_models = $this->prepareModels(); } if ($forcePrepare || $this->_keys === null) { $this->_keys = $this->prepareKeys($this->_models); } }
/** * Returns the data models in the current page. * @return array the list of data models in the current page. */ public function getModels() { $this->prepare(); return $this->_models; } /** * Sets the data models in the current page.
/** * Returns the number of data models in the current page. * @return int the number of data models in the current page. */ public function getCount() { return count($this->getModels()); } /** * Returns the total number of data models. * When [[pagination]] is false, this returns the same value as [[count]]. * Otherwise, it will call [[prepareTotalCount()]] to get the count.
/** * Renders the summary text. */ public function renderSummary() { $count = $this->dataProvider->getCount(); if ($count <= 0) { return ''; } $summaryOptions = $this->summaryOptions; $tag = ArrayHelper::remove($summaryOptions, 'tag', 'div'); if (($pagination = $this->dataProvider->getPagination()) !== false) {
* @return string|bool the rendering result of the section, or false if the named section is not supported. */ public function renderSection($name) { switch ($name) { case '{summary}': return $this->renderSummary(); case '{items}': return $this->renderItems(); case '{pager}': return $this->renderPager(); case '{sorter}': return $this->renderSorter();
public function renderSection($name) { switch ($name) { case '{errors}': return $this->renderErrors(); default: return parent::renderSection($name); } } /** * Returns the options for the grid view JS widget. * @return array the options
* Runs the widget. */ public function run() { if ($this->showOnEmpty || $this->dataProvider->getCount() > 0) { $content = preg_replace_callback('/{\\w+}/', function ($matches) { $content = $this->renderSection($matches[0]); return $content === false ? $matches[0] : $content; }, $this->layout); } else { $content = $this->renderEmpty(); }
{ if ($this->showOnEmpty || $this->dataProvider->getCount() > 0) { $content = preg_replace_callback('/{\\w+}/', function ($matches) { $content = $this->renderSection($matches[0]); return $content === false ? $matches[0] : $content; }, $this->layout); } else { $content = $this->renderEmpty(); } $options = $this->options; $tag = ArrayHelper::remove($options, 'tag', 'div');
{ $view = $this->getView(); GridViewAsset::register($view); $id = $this->options['id']; $options = Json::htmlEncode(array_merge($this->getClientOptions(), ['filterOnFocusOut' => $this->filterOnFocusOut])); $view->registerJs("jQuery('#$id').yiiGridView($options);"); parent::run(); } /** * Renders validator errors of filter model. * @return string the rendering result. */
try { /* @var $widget Widget */ $config['class'] = get_called_class(); $widget = Yii::createObject($config); $out = ''; if ($widget->beforeRun()) { $result = $widget->run(); $out = $widget->afterRun($result); } } catch (\Exception $e) { // close the output buffer opened above if it has not been closed already if (ob_get_level() > 0) { ob_end_clean();
'url' => \yii\helpers\Url::to(['/site/search_in_specifications']), 'dataType' => 'json', 'data' => new JsExpression("function(params) { return {text:params.term, type:'year'}; }") ], 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'), 'templateResult' => new JsExpression('function(city) { return city.text; }'), 'templateSelection' => new JsExpression('function (city) { return city.text; }'), ] ]), ], //'mileage', //'displacement',
{ $_obInitialLevel_ = ob_get_level(); ob_start(); ob_implicit_flush(false); extract($_params_, EXTR_OVERWRITE); try { require $_file_; return ob_get_clean(); } catch (\Exception $e) { while (ob_get_level() > $_obInitialLevel_) { if (!@ob_end_clean()) { ob_clean(); }
$this->renderers[$ext] = Yii::createObject($this->renderers[$ext]); } /* @var $renderer ViewRenderer */ $renderer = $this->renderers[$ext]; $output = $renderer->render($this, $viewFile, $params); } else { $output = $this->renderPhpFile($viewFile, $params); } $this->afterRender($viewFile, $params, $output); } array_pop($this->_viewFiles); $this->context = $oldContext;
* @throws InvalidCallException if the view cannot be resolved. * @see renderFile() */ public function render($view, $params = [], $context = null) { $viewFile = $this->findViewFile($view, $context); return $this->renderFile($viewFile, $params, $context); } /** * Finds the view file based on the given view name. * @param string $view the view name or the [path alias](guide:concept-aliases) of the view file. Please refer to [[render()]] * on how to specify this parameter.
* These parameters will not be available in the layout. * @return string the rendering result. * @throws InvalidArgumentException if the view file or the layout file does not exist. */ public function render($view, $params = []) { $content = $this->getView()->render($view, $params, $this); return $this->renderContent($content); } /** * Renders a static string by applying a layout. * @param string $content the static string being rendered
{ $searchModel = new ProductSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } /** * Displays a single Product model. * @param integer $_id
$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 = [ 'page' => '3', 'sort' => 'car_model', ];