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 … 819 820 821 … 1,067 ถัดไป

Projects

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

Recent Posts

  • Markdown: มาเริ่มเขียนกันเถอะ
  • jQuery: TabulatorPlus
  • จัดคิวยังไงดี Redis / RabbitMQ
  • Angular: TabulatorPlus
  • Playwright: Environment

Archives

Categories

  • AI (23)
  • Businesses (15)
  • Design (43)
    • UX/UI (12)
  • Histories (10)
  • Life (93)
    • Books (37)
    • Cartoon (3)
    • Sci-Fi (4)
    • Tips and Tricks (25)
    • พุทธ (5)
  • Network (132)
    • Apache HTTP Server (15)
    • IOT (1)
    • Nginx (29)
    • Stalwart (5)
  • Operating Systems (266)
    • Unix-like (193)
      • Android (15)
        • F-Droid (5)
      • Homebrew (18)
      • iPhone (8)
      • Linux (116)
      • macOS (97)
        • OrbStack (11)
      • Oh My ZSH (4)
      • Shell Script (34)
      • SSH (11)
    • Windows (117)
      • PowerShell (24)
      • WSL (24)
  • Programming (717)
    • .NET (19)
      • .NET Core EF (6)
      • C# (17)
    • API (26)
      • REST (5)
      • Swagger (6)
    • Database (181)
      • DBeaver (3)
      • MariaDB (29)
      • MySql (67)
      • Oracle Database (6)
        • 10g (3)
      • PostgreSQL (8)
      • RDBMS (2)
      • SQL Server (85)
        • SSMS (8)
        • T-SQL (26)
      • SQLite (1)
    • PowerBuilder (10)
    • Python (5)
    • Rust (1)
    • System Analyst (SA) (20)
    • Testing (17)
      • Automated Testing (9)
        • Playwright (6)
    • UML (7)
    • Web (376)
      • Backend (239)
        • Golang (1)
        • Java (46)
          • Spring Boot (14)
        • Node.js (1)
        • PHP (192)
          • Laravel (16)
          • Yii (5)
      • Frontend (129)
        • CSS (17)
          • Tailwind CSS (5)
        • JavaScript (117)
          • Angular (3)
          • jQuery (61)
          • Tabulator (16)
          • Vue.js (5)
      • WordPress (25)
  • Programs (88)
    • Excel (10)
  • SecDevOps (68)
    • CI/CD (4)
    • Docker (34)
    • GIT (25)
  • Security (56)
  • Uncategorized (1)
  • กฎหมาย (7)

Sirat WordPress Theme By VWThemes

Scroll Up