return $this->values; } /** * {@inheritdoc} * @throws InvalidArgumentException if wrong number of operands have been given. */ public static function fromArrayDefinition($operator, $operands) { if (!isset($operands[0], $operands[1])) { throw new InvalidArgumentException("Operator '$operator' requires two operands."); } return new static($operands[0], $operator, $operands[1]); } }
if (isset($this->conditionClasses[$operator])) { $className = $this->conditionClasses[$operator]; } else { $className = 'yii\db\conditions\SimpleCondition'; } /** @var ConditionInterface $className */ return $className::fromArrayDefinition($operator, $condition); } // hash format: 'column1' => 'value1', 'column2' => 'value2', ... return new HashCondition($condition); }
{ if (is_array($condition)) { if (empty($condition)) { return ''; } $condition = $this->createConditionFromArray($condition); } if ($condition instanceof ExpressionInterface) { return $this->buildExpression($condition, $params); }
*/ private function buildExpressionsFrom(ExpressionInterface $condition, &$params = []) { $parts = []; foreach ($condition->getExpressions() as $condition) { if (is_array($condition)) { $condition = $this->queryBuilder->buildCondition($condition, $params); } if ($condition instanceof ExpressionInterface) { $condition = $this->queryBuilder->buildExpression($condition, $params); } if ($condition !== '') { $parts[] = $condition;
* @param ExpressionInterface|ConjunctionCondition $condition the expression to be built. * @param array $params the binding parameters. * @return string the raw SQL that will not be additionally escaped or quoted. */ public function build(ExpressionInterface $condition, array &$params = []) { $parts = $this->buildExpressionsFrom($condition, $params); if (empty($parts)) { return ''; } if (count($parts) === 1) {
* @throws InvalidArgumentException when $expression building is not supported by this QueryBuilder. */ public function buildExpression(ExpressionInterface $expression, &$params = []) { $builder = $this->getExpressionBuilder($expression); return $builder->build($expression, $params); } /** * Gets object of [[ExpressionBuilderInterface]] that is suitable for $expression. * Uses [[expressionBuilders]] array to find a suitable builder class. *
} $condition = $this->createConditionFromArray($condition); } if ($condition instanceof ExpressionInterface) { return $this->buildExpression($condition, $params); } return (string) $condition; } /**
*/ private function buildExpressionsFrom(ExpressionInterface $condition, &$params = []) { $parts = []; foreach ($condition->getExpressions() as $condition) { if (is_array($condition)) { $condition = $this->queryBuilder->buildCondition($condition, $params); } if ($condition instanceof ExpressionInterface) { $condition = $this->queryBuilder->buildExpression($condition, $params); } if ($condition !== '') { $parts[] = $condition;
* @param ExpressionInterface|ConjunctionCondition $condition the expression to be built. * @param array $params the binding parameters. * @return string the raw SQL that will not be additionally escaped or quoted. */ public function build(ExpressionInterface $condition, array &$params = []) { $parts = $this->buildExpressionsFrom($condition, $params); if (empty($parts)) { return ''; } if (count($parts) === 1) {
* @throws InvalidArgumentException when $expression building is not supported by this QueryBuilder. */ public function buildExpression(ExpressionInterface $expression, &$params = []) { $builder = $this->getExpressionBuilder($expression); return $builder->build($expression, $params); } /** * Gets object of [[ExpressionBuilderInterface]] that is suitable for $expression. * Uses [[expressionBuilders]] array to find a suitable builder class. *
} $condition = $this->createConditionFromArray($condition); } if ($condition instanceof ExpressionInterface) { return $this->buildExpression($condition, $params); } return (string) $condition; } /**
* @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; } $command = $db->createCommand($sql, $params);
*/ public function all($db = null) { if ($this->emulateExecution) { return []; } $rows = $this->createCommand($db)->queryAll(); return $this->populate($rows); } /** * Converts the raw query results into the format as specified by this query. * This method is internally used to convert the data fetched from database
* @param Connection $db the DB connection used to create the DB command. * If null, the DB connection returned by [[modelClass]] will be used. * @return array|ActiveRecord[] the query results. If the query results in nothing, an empty array will be returned. */ public function all($db = null) { return parent::all($db); } /** * {@inheritdoc} */ public function prepare($builder)
if($widget_id){ $widgetModel = Widget::findOne($widget_id); $where = ['and',['and',['not in','id',$widgetModel->id],['type'=>$widgetModel->type]],['status'=>1]]; }else{ $where = ['and',['recommend'=>1],['status'=>1]]; } return Widget::find()->where($where)->orderBy('id',SORT_DESC)->limit(3)->asArray()->all(); } /*关联用户表*/ public function getUserInfo(){ return $this->hasOne(Member::className(),['id'=>'u_id'])->select(['username','province','city','avatar']); }
} public function init() { parent::init(); // TODO: Change the autogenerated stub //查询推荐组件 $recommend_widget = \common\models\Widget::recommend(); //查询推荐新闻 $recommend_news = \common\models\News::recommend(); //查询推荐案例 $recommend_case = \common\models\Cases::recommend(); $recommend = array( 'recommend_news' => $recommend_news,
*/ public function __construct($config = []) { if (!empty($config)) { Yii::configure($this, $config); } $this->init(); } /** * Initializes the object. * This method is invoked at the end of the constructor after the object is initialized with the * given configuration.
* @param array $config name-value pairs that will be used to initialize the object properties. */ public function __construct($id, $module, $config = []) { $this->id = $id; $this->module = $module; parent::__construct($config); } /** * Declares external actions for the controller. * * This method is meant to be overwritten to declare external actions for the controller.
$dependencies = $this->resolveDependencies($dependencies, $reflection); if (!$reflection->isInstantiable()) { throw new NotInstantiableException($reflection->name); } if (empty($config)) { return $reflection->newInstanceArgs($dependencies); } $config = $this->resolveDependencies($config); if (!empty($dependencies) && $reflection->implementsInterface('yii\base\Configurable')) { // set $config as the last parameter (existing one will be overwritten)
public function get($class, $params = [], $config = []) { if (isset($this->_singletons[$class])) { // singleton return $this->_singletons[$class]; } elseif (!isset($this->_definitions[$class])) { return $this->build($class, $params, $config); } $definition = $this->_definitions[$class]; if (is_callable($definition, true)) { $params = $this->resolveDependencies($this->mergeParams($class, $params));
* @throws InvalidConfigException if the configuration is invalid. * @see \yii\di\Container */ public static function createObject($type, array $params = []) { if (is_string($type)) { return static::$container->get($type, $params); } elseif (is_array($type) && isset($type['class'])) { $class = $type['class']; unset($type['class']); return static::$container->get($class, $params, $type); } elseif (is_callable($type, true)) { return static::$container->invoke($type, $params);
$className = ltrim($this->controllerNamespace . '\\' . str_replace('/', '\\', $prefix) . $className, '\\'); if (strpos($className, '-') !== false || !class_exists($className)) { return null; } if (is_subclass_of($className, 'yii\base\Controller')) { $controller = Yii::createObject($className, [$id, $this]); return get_class($controller) === $className ? $controller : null; } elseif (YII_DEBUG) { throw new InvalidConfigException('Controller class must extend from \\yii\\base\\Controller.'); } return null;
if (($pos = strrpos($route, '/')) !== false) { $id .= '/' . substr($route, 0, $pos); $route = substr($route, $pos + 1); } $controller = $this->createControllerByID($id); if ($controller === null && $route !== '') { $controller = $this->createControllerByID($id . '/' . $route); $route = ''; } return $controller === null ? false : [$controller, $route];
* @param array $params the parameters to be passed to the action * @return mixed the result of the action. * @throws InvalidRouteException if the requested route cannot be resolved into an action successfully. */ public function runAction($route, $params = []) { $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);
$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__ . '/../../common/config/main.php', require __DIR__ . '/../../common/config/main-local.php', require __DIR__ . '/../config/main.php', require __DIR__ . '/../config/main-local.php' ); (new yii\web\Application($config))->run();
$_GET = [ 'widget_id' => '546', ];