20.01.2015 Views

Yii Framework

Yii Framework

Yii Framework

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

16<br />

5. การท าระบบ Login โดยดึงข้อมูล User จากฐานข้อมูล<br />

1. ที่ไดเรคทอรี่ www/<strong>Yii</strong>Training/protected/components/UserIdentity.php ให้แก้ไข ดังนี้<br />

1. ประกาศตัวแปร private $id_user; ภายใต้ Class UserIndentity<br />

2. แก้ไขฟังก์ชั่น authenticate ให้เป็นดังรูปที่ 5-1<br />

รูปที่ 5-1 แสดงการแก้ไขฟังก์ชั่น authenticate<br />

2. ที่ ไ ด เรค ท อรี่ www/<strong>Yii</strong>Training/protected/models/UserLogin.php เพิ่ มฟั ง ก์ ชั่ น<br />

validatePassword ดังรูปที่ 5-2<br />

รูปที่ 5-2 แสดงฟังก์ชั่น validatePassword<br />

3. ทดลองระบบ Login โดยใช้ชื่อ user ที่มีอยู่ในฐานข้อมูลได้ที่ http://localhost/<br />

<strong>Yii</strong>Training/index.php ดังรูปที่ 5-3

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!