Skip to content

PlusMagi's Blog By Pitt Phunsanit

Plus emotional magic to the knowledge of logic.

  • About’s Pitt
Close Button

YII2 : เพิ่มระบบจัดการสมาชิกYII2 : เพิ่มระบบจัดการสมาชิก

2012-10-272012-10-27| phunsanitphunsanit| 0 Comment | 07:00

หลังจากติดตั้ง yii2 ตาม ติดตั้ง yii 2 advance ผ่าน composer ขั้นตอนต่อไปจะเพิ่มระบบสมาชิกแบบที่ใช้ฐานข้อมูล โดยผมเลือกใช้ dektrium/yii2-user เพิ่มคุณสมบัติ

  • ระบบลงทะเบียนสมาชิกและเลือกให้ส่งเมลยืนยันได้
  • login โดยใช้ facebook, ig
  • ขอรหัสผ่านใหม่
  • จัดการข้อมูลส่วนตัว
  • ระบบจัดการสมาชิก

การติดตั้ง

  1. ใช้ command พิมพ์
    composer require "dektrium/yii2-user:0.9.*@dev"

    ตอบ yes ในขั้นตอนนี้จะเป็นการแก้ไขไฟล์ composer.json โดยเพิ่ม “dektrium/yii2-user”: “0.9.*@dev” ใน “require” และติดตั้ง ในโฟลเดอร์ \vendor\dektrium\yii2-user ถ้าไม่ได้ลง composer ไว้ก็ download มาวางไว้ก็ได้
  2. เข้าไปที่ database ลบ ตาราง user ออกไปก่อน แล้ว run command
    php yii migrate/up –migrationPath=@vendor/dektrium/yii2-user/migrations

    ตอบ yes รอจนเห็น message “Migrated up successfully.”
  3. เปิดไฟล์ \common\config\main.php เพิ่ม
    <?php
    return [
     'vendorPath' = dirname (dirname (__DIR__)) . '/vendor',
     'components' = [
    ...
     'urlManager' = [
     'class' = 'yii\web\UrlManager',
     'enablePrettyUrl' = true,
     'showScriptName' = false,
     ],
    ...
     'user' = [
     //'identityClass' = 'app\models\User',
     'identityClass' = 'dektrium\user\models\User',
     'enableAutoLogin' = true,
     ],
     ],
     'modules' = [
    ...
     'user' = [
     'class' = 'dektrium\user\Module',
     'admins' = ['phunsanit'],
     'confirmWithin' = 21600,
     'cost' = 12,
     'enableUnconfirmedLogin' = true,
     ],
    ...
     ],
    ];
    
  4. เปิดไฟล์ D:\xampp\htdocs\advanced\backend\config และ D:\xampp\htdocs\advanced\frontend\config ลบ config user ใน components ออก
    'components' = [
    ...
     'user' = [
     'identityClass' = 'common\models\User',
     'enableAutoLogin' = true,
     ],
    ...
    
  5. สร้าง user ใหม่ โดยไปที่ http://localhost/advanced/frontend/web/user/registration/register
  6. จากนั้น login โดย http://localhost/advanced/frontend/web/user/security/login
  7. แก้ menu ใหม่ใน backend\views\layout\main.php และ backend\views\layout\main.php หาใน array $menuItems โดยดู link ได้จาก List of available actions
  8. ปรับแต่งเพิ่มเติมตามคู่มือ
    • Guide to Yii2-user
    • Yii2-user with Yii2 advanced template

อ่านเพิ่มเติม

  • ใช้ cache ใน YII 2
  • แก้ validation error ใน YII 2
  • Laravel 5 VS Yii 2 เลือกตัวไหนดี
Read MoreRead More

Posts pagination

ก่อนหน้า 1 … 767 768 769 … 980 ถัดไป

Projects

  • Statement Columns Mapping Helper
  • PlusMagi Site Search
  • jQuery Plus Repeater

Recent Posts

  • AI:thClaws
  • Laravel: php artisan tinker
  • Line: API มันทำอะไรได้บ้าง
  • Laravel: reset password
  • AWS S3 คืออะไร ? คู่มือครบจบสำหรับผู้เริ่มต้น

Archives

Categories

  • AI (10)
  • Businesses (4)
  • Design (37)
    • UX/UI (6)
  • DevOps (55)
    • CI/CD (2)
    • Docker (29)
    • GIT (25)
  • Histories (10)
  • Life (75)
    • Books (28)
    • Tips and Tricks (15)
    • พุทธ (5)
  • Network (115)
    • Apache HTTP Server (13)
    • IOT (1)
    • Nginx (27)
    • Stalwart (5)
  • Operating Systems (243)
    • Unix-like (172)
      • Android (13)
      • iPhone (5)
      • Linux (107)
      • macOS (85)
        • Homebrew (15)
        • OrbStack (10)
      • Oh My ZSH (4)
      • Shell Script (32)
      • SSH (11)
    • Windows (111)
      • PowerShell (23)
      • WSL (24)
  • Programming (652)
    • .NET (18)
      • .NET Core EF (5)
      • C# (17)
    • API (21)
      • REST (5)
      • Swagger (6)
    • Database (173)
      • DBeaver (3)
      • MariaDB (26)
      • MySql (64)
      • Oracle Database (5)
        • 10g (2)
      • PostgreSQL (6)
      • RDBMS (1)
      • SQL Server (84)
        • SSMS (8)
        • T-SQL (26)
      • SQLite (1)
    • PowerBuilder (10)
    • Python (1)
    • Rust (1)
    • System Analyst (SA) (3)
    • Testing (11)
      • Automated Testing (3)
        • Playwright (2)
    • UML (2)
    • Web (343)
      • Backend (218)
        • Golang (1)
        • Java (44)
          • Spring Boot (14)
        • Node.js (1)
        • PHP (173)
          • Laravel (16)
          • Yii (5)
      • Frontend (123)
        • CSS (17)
          • Tailwind CSS (5)
        • JavaScript (111)
          • Angular (2)
          • jQuery (60)
          • Tabulator (11)
          • Vue.js (3)
      • WordPress (25)
  • Programs (73)
    • Excel (10)
  • Security (47)
  • กฎหมาย (6)

Sirat WordPress Theme By VWThemes

Scroll Up