yii中的登入如何實作
#1、建立資料表shop_admin
CREATE TABLE `shop_admin` ( `adminid` int(10) UNSIGNED NOT NULL COMMENT '主键ID', `adminuser` varchar(32) NOT NULL DEFAULT '' COMMENT '管理员账号', `adminpass` char(32) NOT NULL DEFAULT '' COMMENT '管理员密码', `adminemail` varchar(50) NOT NULL DEFAULT '' COMMENT '管理员邮箱', `logintime` int(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '登陆时间', `loginip` bigint(20) NOT NULL DEFAULT '0' COMMENT '登陆IP', `createtime` int(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间' ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
#2、登陸頁面
<?php use yii\bootstrap\ActiveForm; use yii\helpers\Html; $form = ActiveForm::begin([ 'id' => 'abc-form', 'options' => ['class' => 'form-horizontal'], ])?> <?= $form->field($model, 'adminuser')->textInput(['placeholder' => "用户名"])->label('账号') ?> <?= $form->field($model, 'adminpass')->passwordInput()->label('密码') ?> <?= Html::submitButton('提交') ?> <?php ActiveForm::end() ?>
3、控制器
相關文章教學推薦:yii教程
<?php namespace app\controllers; use yii\web\Controller; use app\models\Admin; use Yii; class IndexController extends Controller { public function actionIndex() { // 不使用布局 $this->layout = false; $model = new Admin; // 是否是post提交 if (Yii::$app->request->isPost) { // 获得post提交参数 $post = Yii::$app->request->post(); if($model->login($post)){ return "登陆成功"; } else { return "登陆失败"; } } else { return $this->render("index", ['model' => $model]); } } }
4、模型
<?php namespace app\models; use yii\db\ActiveRecord; use Yii; class Admin extends ActiveRecord { public static function tableName() { return "{{%admin}}"; } public function rules() { return [ ['adminuser', 'required'], ['adminpass', 'required'], // 验证密码是否正确 ['adminpass', 'validatePass'] ]; } public function validatePass() { if (!$this->hasErrors()) { // 判断用户名密码是否正确 $data = self::find() ->where(['adminuser' => $this->adminuser]) ->andwhere(['adminpass' => md5($this->adminpass)]) ->one(); if (is_null($data)) { $this->addError('adminpass', 'adminuser or adminpass error'); } } } public function login($data) { if($this->load($data) && $this->validate()) { // 登陆信息写入session $session = Yii::$app->session; $session->open(); $session->set('adminuser', $this->adminuser); // 更新登陆时间和IP $this->updateAll(['logintime' => time(), 'loginip' => ip2long(Yii::$app->request->userIP)], ['adminuser' => $this->adminuser]); return true; } return false; } }
更多yii程式設計入門教程,請關注PHP中文網。
#以上是yii中的登入如何實現的詳細內容。更多資訊請關注PHP中文網其他相關文章!

laravelimplementsmvcbySeparationTheApplicationIntomodel(dataandLogic),查看(演示)和controller(userInputhandling).inlaravel,thisissupportedbydbybytoolsandConventionsThatenHancedEvelapentpleflasseffeffereft effervage efferceptife.forexample

tobuildRobustWebapplicationswithyii,MasterTheSeskills:1)MvCarchitectureForstructuringApplications,2)ActivereCordForefifficdataBaseOperations,3)widgetsystemporreusableReusableSueuiComponents,4)驗證和驗證和驗證,5)cachingforpermificatization cachingforpermifications

TobecomeasuccessfulYiideveloper,youneed:1)PHPmastery,2)understandingofMVCarchitecture,3)Yiiframeworkproficiency,4)databasemanagementskills,5)front-endknowledge,6)APIdevelopmentexpertise,7)testinganddebuggingcapabilities,8)versioncontrolproficiency,9)

theSostCommonErrorsinyiiframeWorkare“ unknownproperty”,“無效configuration”,“ classNotfound”和“ valianationerationerrors” .1。 “ Unknownerproperty” errorSoccurWhenAccessingNon-existentSistentProperties; SusePropertiesexi; Susepropertiesexi;

歐洲Yii開發者需具備的關鍵技能包括:1.Yii框架精通,2.PHP熟練度,3.數據庫管理,4.前端技能,5.RESTfulAPI開發,6.版本控制系統,7.測試與調試,8.安全知識,9.敏捷方法論,10.軟技能,11.本地化與國際化,12.持續學習,這些技能使開發者在歐洲市場中脫穎而出。

Yes,theYiicommunityisstillactiveandvibrant.1)TheofficialYiiforumremainsaresourcefordiscussionsandsupport.2)TheGitHubrepositoryshowsregularcommitsandpullrequests,indicatingongoingdevelopment.3)StackOverflowcontinuestohostYii-relatedquestionsandhigh-qu

crigatingalaravel projectToyiiishallingButachieffable withiefleflant.1)mapoutlaravel組件likeoutes,控制器和模型。 2)Translatelaravel's sartisancancancommandeloequorentoottooyii的giiandeteverecordeba

軟技能對Yii開發者至關重要,因為它們促進團隊溝通和協作。 1)有效溝通確保項目進展順利,如通過清晰的API文檔和定期會議。 2)協作通過Yii的工具如Gii增強團隊互動,提高開發效率。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

WebStorm Mac版
好用的JavaScript開發工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

SublimeText3漢化版
中文版,非常好用

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)