yii2怎麼使用user元件
1、先安裝yii2 user元件
composer require "dektrium/yii2-user:0.9.*@dev"
2、然後進行設定
'modules' => [ 'user' => [ 'class' => 'dektrium\user\Module', 'confirmWithin' => 21600, 'cost' => 12, 'admins' => ['admin'] ], ],
3、注意事項
(相關教學推薦:yii框架)
同時刪除原本的user配置
另外要注意自己寫的控制器,model,資料庫這些都不能有user
最後執行$ php yii migrate/up --migrationPath=@vendor/dektrium/yii2-user/migrations
這樣就安裝完畢。
4. 使用yii2-user
下面是對應功能的url,其餘使用和yii2自帶的user差不多的
/user/registration/register Displays registration form /user/registration/resend Displays resend form /user/registration/confirm Confirms a user (requires id and token query params) /user/security/login Displays login form /user/security/logout Logs the user out (available only via POST method) /user/recovery/request Displays recovery request form /user/recovery/reset Displays password reset form (requires id and token query params) /user/settings/profile Displays profile settings form /user/settings/account Displays account settings form (email, username, password) /user/settings/networks Displays social network accounts settings page /user/profile/show Displays user's profile (requires id query param) /user/admin/index Displays user management interface
例如:
<div class="login-strip"> <?php if(Yii::$app->user->isGuest){ ?> <?= Html::a("<i class='icon-plus'></i> 注 册",['/user/registration/register']); ?> | <?= Html::a("<i class='icon-signin'></i> 登 录",['/user/security/login']); ?> <?php } else { ?> <?= Html::a("<i class='icon-signout'></i> 退出",['/user/security/logout']); ?> <?php } ?> </div>
PHP中文網,大量thinkphp教學,歡迎學習!
以上是yii2怎麼使用user元件的詳細內容。更多資訊請關注PHP中文網其他相關文章!