if ($values instanceof Query) { return $this->buildSubqueryInCondition($operator, $column, $values, $params); } if (!is_array($values) && !$values instanceof \Traversable) { // ensure values is an array $values = (array) $values; } if ($column instanceof \Traversable || count($column) > 1) { return $this->buildCompositeInCondition($operator, $column, $values, $params); } elseif (is_array($column)) { $column = reset($column); } $sqlValues = []; foreach ($values as $i => $value) { if (is_array($value) || $value instanceof \ArrayAccess) { $value = isset($value[$column]) ? $value[$column] : null;
} if (!is_array($values) && !$values instanceof \Traversable) { // ensure values is an array $values = (array) $values; } if ($column instanceof \Traversable || count($column) > 1) { return $this->buildCompositeInCondition($operator, $column, $values, $params); } elseif (is_array($column)) { $column = reset($column); } $sqlValues = [];
public function buildHashCondition($condition, &$params) { $parts = []; foreach ($condition as $column => $value) { if (ArrayHelper::isTraversable($value) || $value instanceof Query) { // IN condition $parts[] = $this->buildInCondition('IN', [$column, $value], $params); } else { if (strpos($column, '(') === false) { $column = $this->db->quoteColumnName($column); } if ($value === null) { $parts[] = "$column IS NULL";
} else { $method = 'buildSimpleCondition'; } array_shift($condition); return $this->$method($operator, $condition, $params); } else { // hash format: 'column1' => 'value1', 'column2' => 'value2', ... return $this->buildHashCondition($condition, $params); } } /** * Creates a condition based on column-value pairs. * @param array $condition the condition specification.
*/ public function buildAndCondition($operator, $operands, &$params) { $parts = []; foreach ($operands as $operand) { if (is_array($operand)) { $operand = $this->buildCondition($operand, $params); } if ($operand instanceof Expression) { foreach ($operand->params as $n => $v) { $params[$n] = $v; } $operand = $operand->expression;
if (isset($this->conditionBuilders[$operator])) { $method = $this->conditionBuilders[$operator]; } else { $method = 'buildSimpleCondition'; } array_shift($condition); return $this->$method($operator, $condition, $params); } else { // hash format: 'column1' => 'value1', 'column2' => 'value2', ... return $this->buildHashCondition($condition, $params); } } /**
* @param string|array $condition * @param array $params the binding parameters to be populated * @return string the WHERE clause built from [[Query::$where]]. */ public function buildWhere($condition, &$params) { $where = $this->buildCondition($condition, $params); return $where === '' ? '' : 'WHERE ' . $where; } /** * @param array $columns
$params = empty($params) ? $query->params : array_merge($params, $query->params); $clauses = [ $this->buildSelect($query->select, $params, $query->distinct, $query->selectOption), $this->buildFrom($query->from, $params), $this->buildJoin($query->join, $params), $this->buildWhere($query->where, $params), $this->buildGroupBy($query->groupBy), $this->buildHaving($query->having, $params), ]; $sql = implode($this->separator, array_filter($clauses)); $sql = $this->buildOrderByAndLimit($sql, $query->orderBy, $query->limit, $query->offset);
$modelClass = $this->modelClass; if ($db === null) { $db = $modelClass::getDb(); } if ($this->sql === null) { list ($sql, $params) = $db->getQueryBuilder()->build($this); } else { $sql = $this->sql; $params = $this->params; } return $db->createCommand($sql, $params);
$offset = $this->offset; $this->select = [$selectExpression]; $this->orderBy = null; $this->limit = null; $this->offset = null; $command = $this->createCommand($db); $this->select = $select; $this->orderBy = $order; $this->limit = $limit; $this->offset = $offset;
$modelClass = $this->modelClass; if ($db === null) { $db = $modelClass::getDb(); } if ($this->sql === null) { return parent::queryScalar($selectExpression, $db); } return (new Query)->select([$selectExpression]) ->from(['c' => "({$this->sql})"]) ->params($this->params) ->createCommand($db)
*/ public function count($q = '*', $db = null) { if ($this->emulateExecution) { return 0; } return $this->queryScalar("COUNT($q)", $db); } /** * Returns the sum of the specified column values. * @param string $q the column name or expression. * Make sure you properly [quote](guide:db-dao#quoting-table-and-column-names) column names in the expression.
$model->joinWith(['category b' => function ($query) use ($search) { $query->andFilterWhere(['b.id'=>$search['category_id']]); }]); } $pagination = new Pagination([ 'totalCount' => (clone $model)->count(), 'defaultPageSize' => 16 ]); $model->orderBy([ 'paid_till' => SORT_DESC, 'created_at' => SORT_DESC
$args = $this->controller->bindActionParams($this, $params); Yii::trace('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::trace("Route requested: '$route'", __METHOD__); $this->requestedRoute = $route; $result = $this->runAction($route, $params); if ($result instanceof Response) { return $result; } else { $response = $this->getResponse(); if ($result !== null) { $response->data = $result;
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 = [ 'category_id' => [ '16', ], ];