kcu.constraint_name = rc.constraint_name WHERE rc.constraint_schema = database() AND kcu.table_schema = database() AND rc.table_name = :tableName AND kcu.table_name = :tableName1 SQL; try { $rows = $this->db->createCommand($sql, [':tableName' => $table->name, ':tableName1' => $table->name])->queryAll(); $constraints = []; foreach ($rows as $row) { $constraints[$row['constraint_name']]['referenced_table_name'] = $row['referenced_table_name']; $constraints[$row['constraint_name']]['columns'][$row['column_name']] = $row['referenced_column_name']; } $table->foreignKeys = []; foreach ($constraints as $constraint) { $table->foreignKeys[] = array_merge( [$constraint['referenced_table_name']], $constraint['columns'] ); }
SQL; try { $rows = $this->db->createCommand($sql, [':tableName' => $table->name, ':tableName1' => $table->name])->queryAll(); $constraints = []; foreach ($rows as $row) { $constraints[$row['constraint_name']]['referenced_table_name'] = $row['referenced_table_name']; $constraints[$row['constraint_name']]['columns'][$row['column_name']] = $row['referenced_column_name']; } $table->foreignKeys = []; foreach ($constraints as $constraint) { $table->foreignKeys[] = array_merge( [$constraint['referenced_table_name']],
protected function loadTableSchema($name) { $table = new TableSchema; $this->resolveTableNames($table, $name); if ($this->findColumns($table)) { $this->findConstraints($table); return $table; } else { return null; } }
if ($db->enableSchemaCache && !in_array($name, $db->schemaCacheExclude, true)) { /* @var $cache Cache */ $cache = is_string($db->schemaCache) ? Yii::$app->get($db->schemaCache, false) : $db->schemaCache; if ($cache instanceof Cache) { $key = $this->getCacheKey($name); if ($refresh || ($table = $cache->get($key)) === false) { $this->_tables[$name] = $table = $this->loadTableSchema($realName); if ($table !== null) { $cache->set($key, $table, $db->schemaCacheDuration, new TagDependency([ 'tags' => $this->getCacheTag(), ])); } } else {
* @throws InvalidConfigException if the table for the AR class does not exist. */ public static function getTableSchema() { $tableSchema = static::getDb() ->getSchema() ->getTableSchema(static::tableName()); if ($tableSchema === null) { throw new InvalidConfigException('The table does not exist: ' . static::tableName()); } return $tableSchema;
/** * @inheritdoc */ public static function populateRecord($record, $row) { $columns = static::getTableSchema()->columns; foreach ($row as $name => $value) { if (isset($columns[$name])) { $row[$name] = $columns[$name]->phpTypecast($value); } } parent::populateRecord($record, $row);
/* @var $class ActiveRecord */ $class = $this->modelClass; if ($this->indexBy === null) { foreach ($rows as $row) { $model = $class::instantiate($row); $modelClass = get_class($model); $modelClass::populateRecord($model, $row); $models[] = $model; } } else { foreach ($rows as $row) { $model = $class::instantiate($row); $modelClass = get_class($model);
public function populate($rows) { if (empty($rows)) { return []; } $models = $this->createModels($rows); if (!empty($this->join) && $this->indexBy === null) { $models = $this->removeDuplicatedModels($models); } if (!empty($this->with)) { $this->findWith($this->with, $models); }
* 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; } else { return null; } }
if (!empty($recommend)) { $sourceModels->andWhere(['recommend' => SourceContentModel::RECOMMEND_YES]); } if (!empty($category)) { $sourceModels->joinWith('categoryEntityTerm')->where(['term_id' => $category]); } $categories = Term::find()->where(['id' => $category])->one(); $dataProvider = new ActiveDataProvider([ 'query' => $sourceModels ]); return $this->render('index', [ 'dataProvider' => $dataProvider, 'categories' => $categories,
$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; } else {
$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();
if (GRAZIO_ADMIN) { $config = require(__DIR__ . '/../app/config/admin.php'); }else{ $config = require(__DIR__ . '/../app/config/web.php'); } $config = yii\helpers\ArrayHelper::merge($config, $local); (new yii\web\Application($config))->run();
$_GET = [ 'category' => '55', 'page' => '2', ];