$readConcern = $this->getReadConcern(); if ($readConcern !== null) { $options['readConcern'] = $readConcern; } try { $this->beginProfile($token, __METHOD__); $query = new \MongoDB\Driver\Query($this->document, $options); $this->db->open(); $cursor = $this->db->manager->executeQuery($databaseName . '.' . $collectionName, $query, $this->getReadPreference()); $cursor->setTypeMap($this->db->typeMap); $this->endProfile($token, __METHOD__); } catch (RuntimeException $e) { $this->endProfile($token, __METHOD__); throw new Exception($e->getMessage(), $e->getCode(), $e); }
unset($options['skip']); } else { $options['skip'] = (int)$options['skip']; } } return $this->query($collectionName, $options); } /** * Updates a document and returns it. * @param $collectionName * @param array $condition query condition
*/ public function find($condition = [], $fields = [], $options = []) { if (!empty($fields)) { $options['projection'] = $fields; } return $this->database->createCommand()->find($this->name, $condition, $options); } /** * Returns a single document. * @param array $condition query condition * @param array $fields fields to be selected
if (!empty($this->orderBy)) { $options['sort'] = $this->orderBy; } $options['limit'] = $this->limit; $options['skip'] = $this->offset; $cursor = $this->getCollection($db)->find($this->composeCondition(), $this->select, $options); return $cursor; } /** * Fetches rows from the given Mongo cursor.
*/ public function one($db = null) { if (!empty($this->emulateExecution)) { return false; } $cursor = $this->buildCursor($db); return $this->fetchRows($cursor, false); } /** * Returns the query result as a scalar value. * The value returned will be the first column in the first row of the query results.
* @return ActiveRecord|array|null a single row of query result. Depending on the setting of [[asArray]], * the query result may be either an array or an ActiveRecord object. Null will be returned * if the query results in nothing. */ public function one($db = null) { $row = parent::one($db); if ($row !== false) { $models = $this->populate([$row]); return reset($models) ?: null; } return null; }
/** * {@inheritdoc} * @return static|null ActiveRecord instance matching the condition, or `null` if nothing matches. */ public static function findOne($condition) { return static::findByCondition($condition)->one(); } /** * {@inheritdoc} * @return static[] an array of ActiveRecord instances, or an empty array if nothing matches. */
return $this->render('my_recommended_cars', []); } public function actionView_car($n){ $car = Product::findOne(['number'=>intval($n)]); $isOrder = Order::findOne(['productNumber'=>intval($n), 'userId'=>Yii::$app->user->identity->_id]); return $this->render('view_car', ['car'=>$car, 'isOrder'=>$isOrder]); } public function actionOrder_car($n){ if (Yii::$app->user->isGuest) {
$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 = [ 'n' => '113764', ];