<?php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=mpro',
'username' => 'mpro',
'password' => '1234',
'charset' => 'utf8',
//'tablePrefix' => 'tbl_',
];
./yii migrate/create create_news_table
Yii Migration Tool (based on Yii v2.0.4)
Create new migration '/var/www/admin/www/mpro.com/migrations/m150522_071237_create_news_table.php'? (yes|no) [no]:y
New migration created successfully.
root@s05657775:/var/www/admin/www/mpro.com# ./yii migrate up
Yii Migration Tool (based on Yii v2.0.4)
Total 1 new migration to be applied:
m150522_071237_create_news_table
Apply the above migration? (yes|no) [no]:y
*** applying m150522_071237_create_news_table
*** applied m150522_071237_create_news_table(time: 0.002s)
Migrated up successfully.
<?php
use yii\db\Schema;
use yii\db\Migration;
class m150522_063406_create_news_table extends Migration
{
public function up()
{
$this->createTable('news', [
'id' => 'pk',
'title' => Schema::TYPE_STRING . ' NOT NULL',
'content' => Schema::TYPE_TEXT,
]);
$this->insert('news', [
'title' => 'test 1',
'content' => 'content 1',
]);
}
public function down()
{
$this->delete('news', ['id' => 1]);
$this->dropTable('news');
}
}
<?php
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'grBNpbe5EkZVUy7lbClpf4Q7E7Cu_gye',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller>/<action>' => '<controller>/<action>',
]
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => require(__DIR__ . '/db.php'),
],
'params' => $params,
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = 'yii\debug\Module';
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = ['class' => \yii\gii\Module::className(),
'allowedIPs' => ['*']
];
}
return $config;