فعال سازی جدول پیش فرض user در فریم ورک Yii2
در فریم ورک yii2 نسخه advanced به صورت پیش فرض مدل user وجود دارد
که در فولدر common و در قسمت models قرار داده شده است.
زمانی که شما پروژه ای را اجرا می کنید (نسخه advance ) امکاناتی نظیر لاگین , لاگ اوت ، ثبت نام و فراموشی رمز عبور به صورت پیش فرض در frontend و در siteController وجود دارد
table user در دیتابیس مرتبط با امکانات بالا در فولدر migration واقع در فولدر console قرار دارد که به شرح زیر می باشد :
<?php use yii\db\Migration; class m130524_201442_init extends Migration { public function up() { $tableOptions = null; if ($this->db->driverName === 'mysql') { // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; } $this->createTable('{{%user}}', [ 'id' => $this->primaryKey(), 'username' => $this->string()->notNull()->unique(), 'auth_key' => $this->string(32)->notNull(), 'password_hash' => $this->string()->notNull(), 'password_reset_token' => $this->string()->unique(), 'email' => $this->string()->notNull()->unique(), 'status' => $this->smallInteger()->notNull()->defaultValue(10), 'created_at' => $this->integer()->notNull(), 'updated_at' => $this->integer()->notNull(), ], $tableOptions); } public function down() { $this->dropTable('{{%user}}'); } }
توجه : در رابطه با migration ها در
اینجا
توضیح داده شده است .
در صورتی که نیاز به تغییر اطلاعات بالا داشتید می توانید آن را تغییر دهید .
برای اجرای کد بالا و پیاده سازی در دیتابیس (ایجاد جدول user) باید در cmd خود کد زیر را اجرا نمایید :
yii migrate --migrationTable=migrations