return $operator === 'IN' ? '0=1' : ''; } if ($values instanceof Query) { return $this->buildSubqueryInCondition($operator, $column, $values, $params); } $values = (array) $values; if (count($column) > 1) { return $this->buildCompositeInCondition($operator, $column, $values, $params); } if (is_array($column)) { $column = reset($column); } foreach ($values as $i => $value) { if (is_array($value)) { $value = isset($value[$column]) ? $value[$column] : null;
if ($values instanceof Query) { return $this->buildSubqueryInCondition($operator, $column, $values, $params); } $values = (array) $values; if (count($column) > 1) { return $this->buildCompositeInCondition($operator, $column, $values, $params); } if (is_array($column)) { $column = reset($column); }
public function buildHashCondition($condition, &$params) { $parts = []; foreach ($condition as $column => $value) { if (is_array($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 !== '') { $parts[] = $operand; } } if (!empty($parts)) {
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); } } /**
*/ public function buildAndCondition($operator, $operands, &$params) { $parts = []; foreach ($operands as $operand) { if (is_array($operand)) { $operand = $this->buildCondition($operand, $params); } if ($operand !== '') { $parts[] = $operand; } } if (!empty($parts)) {
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);
$limit = $this->limit; $offset = $this->offset; $this->select = [$selectExpression]; $this->limit = null; $this->offset = null; $command = $this->createCommand($db); $this->select = $select; $this->limit = $limit; $this->offset = $offset; if (empty($this->groupBy) && empty($this->having) && empty($this->union) && !$this->distinct) {
/** * @inheritdoc */ protected function queryScalar($selectExpression, $db) { if ($this->sql === null) { return parent::queryScalar($selectExpression, $db); } /* @var $modelClass ActiveRecord */ $modelClass = $this->modelClass; if ($db === null) { $db = $modelClass::getDb(); }
* If this parameter is not given (or null), the `db` application component will be used. * @return integer|string number of records. The result may be a string depending on the * underlying database engine and to support integer values higher than a 32bit PHP integer can handle. */ public function count($q = '*', $db = null) { 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.
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(); $query->limit($pagination->getLimit())->offset($pagination->getOffset()); } if (($sort = $this->getSort()) !== false) { $query->addOrderBy($sort->getOrders()); }
* * @param boolean $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.
*/ public function __get($name) { $getter = 'get' . $name; if (method_exists($this, $getter)) { // read property, e.g. getName() return $this->$getter(); } else { // behavior property $this->ensureBehaviors(); foreach ($this->_behaviors as $behavior) { if ($behavior->canGetProperty($name)) { return $behavior->$name;
$this->_adp = new ActiveDataProvider([ 'query' => $query, 'pagination' => !empty($options['pagination']) ? $options['pagination'] : [] ]); foreach($this->_adp->models as $model){ $this->_items[] = new NewsObject($model); } } return $this->_items; }
public static function __callStatic($method, $params) { $name = (new \ReflectionClass(self::className()))->getShortName(); if (!isset(self::$classes[$name])) { self::$classes[$name] = new static(); } return call_user_func_array([self::$classes[$name], 'api_' . $method], $params); } /** * Wrap text with liveEdit tags, which later will fetched by jquery widget * @param $text * @param $path
class NewsController extends \yii\web\Controller { public function actionIndex($tag = null) { return $this->render('index',[ 'news' => News::items(['tags' => $tag, 'pagination' => ['pageSize' => 2]]) ]); } public function actionView($slug) { $news = News::get($slug);
$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); Yii::$app->controller = $oldController; return $result; } else { $id = $this->getUniqueId(); throw new InvalidRouteException('Unable to resolve the request "' . ($id === '' ? $route : $id . '/' . $route) . '".');
$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__ . '/app/config/web.php'); (new yii\web\Application($config))->run();
$_GET = [ 'tag' => 'CLStables', ]; $_SERVER = [ 'TMPDIR' => '/var/www/clients/client1/web12/tmp', 'PHPRC' => '/etc/', 'TEMP' => '/var/www/clients/client1/web12/tmp', 'PHP_DOCUMENT_ROOT' => '/var/www/clients/client1/web12', 'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin', 'PWD' => '/var/www/php-fcgi-scripts/web12', 'SHLVL' => '0', 'TMP' => '/var/www/clients/client1/web12/tmp', 'PHP_FCGI_MAX_REQUESTS' => '5000', 'HTTP_CONNECTION' => 'close', 'SCRIPT_NAME' => '/index.php', 'REQUEST_URI' => '/news?tag=CLStables', 'QUERY_STRING' => 'tag=CLStables', 'REQUEST_METHOD' => 'GET', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'REDIRECT_URL' => '/news', 'REDIRECT_QUERY_STRING' => 'tag=CLStables', 'REMOTE_PORT' => '55474', 'SCRIPT_FILENAME' => '/var/www/carma.work/web/index.php', 'SERVER_ADMIN' => 'webmaster@carma.work', 'CONTEXT_DOCUMENT_ROOT' => '/var/www/carma.work/web', 'CONTEXT_PREFIX' => '', 'REQUEST_SCHEME' => 'https', 'DOCUMENT_ROOT' => '/var/www/carma.work/web', 'REMOTE_ADDR' => '3.91.43.22', 'SERVER_PORT' => '443', 'SERVER_ADDR' => '173.249.13.44', 'SERVER_NAME' => 'carma.work', 'SERVER_SOFTWARE' => 'Apache', 'SERVER_SIGNATURE' => '', 'HTTP_HOST' => 'carma.work', 'HTTP_REFERER' => 'http://carma.work/news?tag=CLStables', 'HTTP_USER_AGENT' => 'claudebot', 'HTTP_ACCEPT' => '*/*', 'SSL_TLS_SNI' => 'carma.work', 'HTTPS' => 'on', 'PERL5LIB' => '/usr/share/awstats/lib:/usr/share/awstats/plugins', 'SCRIPT_URI' => 'https://carma.work/news', 'SCRIPT_URL' => '/news', 'UNIQUE_ID' => 'ZgafHKwzbxabI6U1uo@6JwAAAAs', 'REDIRECT_STATUS' => '200', 'REDIRECT_SSL_TLS_SNI' => 'carma.work', 'REDIRECT_HTTPS' => 'on', 'REDIRECT_PERL5LIB' => '/usr/share/awstats/lib:/usr/share/awstats/plugins', 'REDIRECT_SCRIPT_URI' => 'https://carma.work/news', 'REDIRECT_SCRIPT_URL' => '/news', 'REDIRECT_UNIQUE_ID' => 'ZgafHKwzbxabI6U1uo@6JwAAAAs', 'FCGI_ROLE' => 'RESPONDER', 'PHP_SELF' => '/index.php', 'REQUEST_TIME_FLOAT' => 1711709980.394911, 'REQUEST_TIME' => 1711709980, ];