国产激情自拍_国产9色视频_丁香花在线电影小说观看 _久久久久国产精品嫩草影院

首頁 > 編程 > PHP > 正文

YII Framework框架使用YIIC快速創(chuàng)建YII應用之migrate用

2020-03-22 20:02:12
字體:
來源:轉載
供稿:網(wǎng)友
PHP YII Framework框架使用YIIC快速創(chuàng)建YII應用之migrate用法實例詳解
本文實例講述了YII Framework框架使用YIIC快速創(chuàng)建YII應用之migrate用法。分享給大家供大家參考,具體如下:yii migrate查看幫助/www/yii_dev/yii/framework# php yiic migrate helpError: Unknown action: helpUSAGE yiic migrate [action] [parameter]DESCRIPTION This command provides support for database migrations. The optional 'action' parameter specifies which specific migration task to perform. It can take these html' target='_blank'>values: up, down, to, create, history, new, mark. If the 'action' parameter is not given, it defaults to 'up'. Each action takes different parameters. Their usage can be found in the following examples.EXAMPLES* yiic migrateApplies ALL new migrations. This is equivalent to 'yiic migrate to'.* yiic migrate create create_user_tableCreates a new migration named 'create_user_table'.* yiic migrate up 3Applies the next 3 new migrations.* yiic migrate downReverts the last applied migration.* yiic migrate down 3Reverts the last 3 applied migrations.* yiic migrate to 101129_185401Migrates up or down to version 101129_185401.* yiic migrate mark 101129_185401Modifies the migration history up or down to version 101129_185401.No actual migration will be performed.* yiic migrate historyShows all previously applied migration information.* yiic migrate history 10Shows the last 10 applied migrations.* yiic migrate newShows all new migrations.* yiic migrate new 10Shows the next 10 migrations that have not been applied.在我們開發(fā)程序的過程中,數(shù)據(jù)庫的結構也是不斷調整的。我們的開發(fā)中要保證代碼和數(shù)據(jù)庫庫的同步。因為我們的應用離不開數(shù)據(jù)庫。例如: 在開發(fā)過程中,我們經(jīng)常需要增加一個新的表,或者我們后期投入運營的產(chǎn)品,可能需要為某一列添加索引。我們必須保持數(shù)據(jù)結構和代碼的一致性。如果代碼和數(shù)據(jù)庫不同步,可能整個系統(tǒng)將無法正常運行。出于這個原因。yii提供了一個數(shù)據(jù)庫遷移工具,可以保持代碼和數(shù)據(jù)庫是同步。方便數(shù)據(jù)庫的回滾和更新。功能正如描述。主要提供了數(shù)據(jù)庫遷移功能。命令格式y(tǒng)iic migrate [action] [parameter]action參數(shù)用來制定執(zhí)行哪一個遷移任務。可以一使用up, down, to, create, history, new, mark.這些命令如果沒有action參數(shù),默認為upparameter根據(jù)action的不同而有所變化。上述例子中給出了說明。官方也給出了詳細的例子。http://www.yiiframework.com/doc/guide/1.1/zh_cn/database.migration#creating-migrations這里不再詳細累述。用到的時候參考使用就可以了。補充:yii2.0使用migrate創(chuàng)建后臺登陸重新創(chuàng)建一張數(shù)據(jù)表來完成后臺登陸驗證為了大家看得明白,直接貼代碼一、使用Migration創(chuàng)建表adminconsole/migrations/m130524_201442_init.phpuse yii/db/Schema;use yii/db/Migration;class m130524_201442_init extends Migration const TBL_NAME = '{{%admin}}'; public function safeUp() $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(self::TBL_NAME, [ 'id' = Schema::TYPE_PK, 'username' = Schema::TYPE_STRING . ' NOT NULL', 'auth_key' = Schema::TYPE_STRING . '(32) NOT NULL', 'password_hash' = Schema::TYPE_STRING . ' NOT NULL', //密碼 'password_reset_token' = Schema::TYPE_STRING, 'email' = Schema::TYPE_STRING . ' NOT NULL', 'role' = Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 10', 'status' = Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 10', 'created_at' = Schema::TYPE_INTEGER . ' NOT NULL', 'updated_at' = Schema::TYPE_INTEGER . ' NOT NULL', ], $tableOptions); $this- createIndex('username', self::TBL_NAME, ['username'],true); $this- createIndex('email', self::TBL_NAME, ['email'],true); public function safeDown() $this- dropTable(self::TBL_NAME);使用命令行來創(chuàng)建admin數(shù)據(jù)庫1、win7下使用命令:在項目根目下,右鍵選擇User composer here(前提是安裝了全局的composer),
yii migrate即創(chuàng)建數(shù)據(jù)表 admin成功2、linux下命令一樣(此處略)二、使用gii創(chuàng)建模型此處略,很簡單的步聚。注:把admin模型創(chuàng)在 backend/models下面 (放哪里看個人喜好)
代碼如下namespace backend/models;use Yii;use yii/base/NotSupportedException;use yii/behaviors/TimestampBehavior;use yii/db/ActiveRecord;use yii/web/IdentityInterface; * This is the model class for table "{{%admin}}". * @property integer $id * @property string $username * @property string $auth_key * @property string $password_hash * @property string $password_reset_token * @property string $email * @property integer $role * @property integer $status * @property integer $created_at * @property integer $updated_atclass AgAdmin extends ActiveRecord implements IdentityInterface const STATUS_DELETED = 0; const STATUS_ACTIVE = 10; const ROLE_USER = 10; const AUTH_KEY = '123456'; * @inheritdoc public static function tableName() return '{{%admin}}'; * @inheritdoc public function behaviors() return [ TimestampBehavior::className(), * @inheritdoc public function rules() return [ [['username', 'email',], 'required'], [['username', 'email'], 'string', 'max' = 255], [['username'], 'unique'], [['username'], 'match', 'pattern'= '/^[a-z]/w*$/i'], [['email'], 'unique'], [['email'], 'email'], ['status', 'default', 'value' = self::STATUS_ACTIVE], ['status', 'in', 'range' = [self::STATUS_ACTIVE, self::STATUS_DELETED]], ['role', 'default', 'value' = self::ROLE_USER], ['auth_key', 'default', 'value' = self::AUTH_KEY], ['role', 'in', 'range' = [self::ROLE_USER]], * @inheritdoc public static function findIdentity($id) return static::findOne(['id' = $id, 'status' = self::STATUS_ACTIVE]); * @inheritdoc public static function findIdentityByAccessToken($token, $type = null) return static::findOne(['access_token' = $token]); //throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.'); * Finds user by username * @param string $username * @return static|null public static function findByUsername($username) return static::findOne(['username' = $username, 'status' = self::STATUS_ACTIVE]); * Finds user by password reset token * @param string $token password reset token * @return static|null public static function findByPasswordResetToken($token) if (!static::isPasswordResetTokenValid($token)) { return null; return static::findOne([ 'password_reset_token' = $token, 'status' = self::STATUS_ACTIVE, * Finds out if password reset token is valid * @param string $token password reset token * @return boolean public static function isPasswordResetTokenValid($token) if (empty($token)) { return false; $expire = Yii::$app- params['user.passwordResetTokenExpire']; $parts = explode('_', $token); $timestamp = (int) end($parts); return $timestamp + $expire = time(); * @inheritdoc public function getId() return $this- getPrimaryKey(); * @inheritdoc public function getAuthKey() return $this- auth_key; * @inheritdoc public function validateAuthKey($authKey) return $this- getAuthKey() === $authKey; * Validates password * @param string $password password to validate * @return boolean if password provided is valid for current user public function validatePassword($password) return Yii::$app- security- validatePassword($password, $this- password_hash); * Generates password hash from password and sets it to the model * @param string $password public function setPassword($password) $this- password_hash = Yii::$app- security- generatePasswordHash($password); * Generates "remember me" authentication key public function generateAuthKey() $this- auth_key = Yii::$app- security- generateRandomString(); * Generates new password reset token public function generatePasswordResetToken() $this- password_reset_token = Yii::$app- security- generateRandomString() . '_' . time(); * Removes password reset token public function removePasswordResetToken() $this- password_reset_token = null;三、使用migrate 為后如初使化一個登陸帳號1、console/controllers創(chuàng)建InitController.php * @author chan maclechan@qq.com namespace console/controllers;use backend/models/Admin ;class InitController extends /yii/console/Controller * Create init user public function actionAdmin() echo "創(chuàng)建一個新用戶 .../n"; // 提示當前操作 $username = $this- prompt('User Name:'); // 接收用戶名 $email = $this- prompt('Email:'); // 接收Email $password = $this- prompt('Password:'); // 接收密碼 $model = new AgAdmin(); // 創(chuàng)建一個新用戶 $model- username = $username; // 完成賦值 $model- email = $email; $model- password = $password; if (!$model- save()) // 保存新的用戶 foreach ($model- getErrors() as $error) // 如果保存失敗,說明有錯誤,那就輸出錯誤信息。 foreach ($error as $e) echo "$e/n"; return 1; // 命令行返回1表示有異常 return 0; // 返回0表示一切OK2、使用命令:在項目根目下,右鍵選擇User composer here(前提是安裝了全局的composer),
yii init/admin到此,打開數(shù)據(jù)表看下,己經(jīng)有了數(shù)據(jù)。四、后臺登陸驗證1、backend/controllers/SiteController.php 里actionLogin方法不用變2、把common/models/LoginForm.php復制到backend/models只要把LoginForm.php里面的方法getUser()修改一個單詞即可,如下public function getUser() if ($this- _user === false) { $this- _user = Admin::findByUsername($this- username); return $this- _user;3、backend/config/main.php 只要修改'user' = [ 'identityClass' = 'backend/models/Admin', 'enableAutoLogin' = true,此外,在作修改時,請注意下命令空不要搞亂了。到此,結束。更多關于Yii相關內容感興趣的讀者可查看本站專題:《Yii框架入門及常用技巧總結》、《php優(yōu)秀開發(fā)框架總結》、《smarty模板入門基礎教程》、《php日期與時間用法總結》、《php面向對象程序設計入門教程》、《php字符串(string)用法總結》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》希望本文所述對大家基于Yii框架的PHP程序設計有所幫助。PHP教程

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
国产激情自拍_国产9色视频_丁香花在线电影小说观看 _久久久久国产精品嫩草影院
欧美日韩在线精品成人综合网| 精品推荐国产麻豆剧传媒| 国产三级香港三韩国三级| 尤物视频在线看| 国产福利三区| 午夜在线不卡| 国产精品综合久久久久| 91亚洲精选| 高清av中文在线字幕观看1| 中文字幕在线视频不卡| 国产男女无套在线播放| 国产精品69一区二区三区| 精品全国在线一区二区| h网址在线观看| 天天爱天天做色综合| 在线观看wwww| 国产一区二区影视| av在线free| 国产精品久久久久久精| 欧美日韩亚洲国内综合网| 国产无遮挡又黄又爽免费软件| 亚洲高清在线免费| 国产免费av在线| 亚洲an天堂an在线观看| 国产精品免费视频二三区| 四虎成年永久免费网站| 国产乱视频在线观看| 亚洲国产日韩成人综合天堂| 最近中文字幕在线中文视频| 日本视频在线观看一区二区三区| 中文字幕国产视频| 浪潮av一区| а√最新版在线天堂| 97影院理论午夜| 国产精品jvid在线观看| 黄色电影网站在线观看| av在线中文| 亚洲成a人v欧美综合天堂麻豆| 国产系列在线观看| 成人福利视频导航| 亚洲精品自拍区在线观看| 国产成人午夜精品| 国产国语**毛片高清视频 | 国产区视频在线| 久青青在线观看视频国产| 亚洲成a人v欧美综合天堂麻豆| 国产黄色片大全| 91亚洲欧美| 在线激情网站| 成av人免费青青久| 国产麻豆精品视频一区二区 | 国产视频精选在线| 日本中文字幕在线观看| 久艹在线视频| 国产粉嫩一区二区三区在线观看| 18av在线视频| 日本视频在线| 中文字幕中文字幕在线中高清免费版 | 久久久久久国产视频| 日本一本久久| 成在在线免费视频| 国产无遮挡在线视频免费观看| 国产无遮挡又黄又爽免费网站| 2020亚洲男人天堂| 四虎成人精品在永久免费| 九九热视频精品在线观看| 国产探花在线观看| 精品一区二区在线欧美| gogo高清在线播放免费| 尤物视频网站在线观看| 在线国产一区二区三区| 成年网站免费入口在线观看| 国产成a人亚洲精v品| 欧美日韩亚洲国内综合网| 国内精品不卡| 亚洲精品aaaa精品| 国产羞羞视频在线观看| 人成在线免费视频| 91这里只有精品| 国产男女猛烈无遮挡免费视频| 91涩漫在线观看c| 国产一卡2卡3卡四卡网站 | 久久久久久91精品色婷婷| 国产国语**毛片高清视频| 国产在线第一页| аⅴ成人天堂中文在线| 国产视频97| 人人干在线视频| 影音先锋中文字幕在线| 国产精品久久精品牛牛影视| 国内精品不卡| 老司机精品视频一区二区| 亚洲精品天堂在线观看| 精品国产一区二区三区四区阿崩| 国产日韩欧美第一页| 国产在线视频网站| 本道综合精品| 免费一区二区在线观看| 亚洲视频日韩| 人人干人人插| 四虎中文字幕| www.av在线视频| 性欧美精品xxxx| wwww在线观看免费视频| 青青草视频在线观看| baoyu777.永久免费视频| 午夜羞羞小视频在线观看| 色综合久久五月天| 毛片网站在线观看| 毛片在线视频| 国产一级又黄| 99热免费观看| 日本成人免费网站| 黄色片大全在线观看| 大香伊人久久| 91视频久色| 男人操女人免费网站| 日本高清中文字幕| 中文字幕在线免费观看| 国产爆初菊在线观看免费视频网站 | 日本免费视频www| 欧美精品一区二区三区免费| 国产中文字幕av| 国产三级香港三韩国三级| 精精国产xxxx视频在线动漫| 麻豆精品传媒视频观看| 国产网红在线观看| sm国产在线调教视频| 麻豆网站在线免费观看| 国产精品视频一区二区免费不卡| 9色在线视频网站| 天天爱天天色| 青青在线视频| av大片在线播放| 天天操天天射天天色| 亚洲欧洲成人| 国产福利小视频在线| 久热国产在线视频| 亚洲综合在线免费| 国产欧美日韩精品综合| 狠狠操狠狠色| 欧美婷婷久久五月精品三区| 国产精选在线观看| 日本三级在线视频| 精品国内自产拍在线视频| 成人av小说网| 性网站在线播放| 伊人电影在线观看| 国产黄色在线网站| 国产视频二区三区| 国产偷激情在线| 尤物在线网址| 国产九九九九| 国产在线www| 国产理论电影在线| 99视频在线观看地址| 另类视频在线| 九九视频在线播放| 夜色资源网av在先锋网站观看| 1区2区3区在线| 中文字幕麻豆| 国产一区二区三区美女秒播| 国产69久久| 午夜视频在线| 中文字幕在线播放网址| 国产美女在线播放| √天堂中文在线| 国产日本在线视频| 精品视频三区| 欧美日韩在线资源| 国产在线观看色| 国产香蕉在线| 99热免费在线观看| 亚洲综合在线不卡| 青青久草在线| 午夜国产视频| 性网站在线观看| 天天操天天艹| 尤物在线视频观看| 欧美xxxxx性| 国产区卡一卡二卡三乱码免费| 国产福利在线看| 欧美精品日韩少妇| 国产欧美日韩第一页| av网站在线播放| 国产亚洲精品久久久久久移动网络 | 日本国产在线| 午夜视频在线看| 在线成人一区| 最近免费中文字幕大全免费第三页| 国产激情自拍视频| 亚洲精品aaaa| 国产午夜在线| 九九热在线视频观看| 2021天堂中文幕一二区在线观| eeuss影院在线| 国产精美视频| 国产麻豆精品视频一区二区| 在线观看中文字幕的网站| 99热在线免费播放|