Bài tập lập trình PHP

47 208 0
Bài tập lập trình PHP

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

LAB THỰC HÀNH PHP Bước 1: làm quen cách gọi hàm, kiện, kế thừa php (lập trình web với php) thực hành với project Quản lý trắc nghiệm Mơ hình xử lý: - Vào thư mục quản lý project wampserver tạo forder [QLTN] - Trong forder [QLTN] tạo file default.php, file default.php học cách sử dụng lệnh include() gọi hàm Chúng ta code file default.php sau: - Trong project QLTN tạo forder [includes] để chứa tất file mà chùng ta muốn include Trong forder [includes] tạo file [config.php] để thiết lập kết nối csdl Ví dụ file config.php code kết nối sau: - - Hướng dẫn sử dụng sessions viết code cho trang login: o Trong forder [includes] tạo file [sessions.php] Trong file [sessions.php] viết code khởi tạo session tạo biến login toàn cục quản lý biến session o - Mở file [default.php] include file sessions.php Tiếp theo tạo trang xử lý kiện: vào thư mục [includes] tạo file [eventHandler.php] viết code sau: - Tiếp theo dựa vào phần xử lý hàm eventHandler() để tạo số trang mà hàm eventHandler cần gọi để xử lý: o Đoạn code dòng 24 hàm eventHandler(): gọi hiển thị trang form login  Trong forder [QLTN] tạo forder [view]: chứa form hiển thị project  Trong forder [view] tạo file [login.php] Ví dụ code form sau (design form theo ý sinh viên) o Dòng 27 hàm eventHandler(): yêu cầu hiển thị form add câu hỏi  Vào forder [view] tạo file [createQuestion.php] Ví dụ design form sau: o Dòng 30 hàm eventHandler(): yêu cầu gọi file xử lý login  Trong forder [QLTN] tạo forder với tên [process]  Trong forder [process] tạo file xử lý login [processLogin.php] File processLogin.php viết code sau: o Dòng 51 file [eventHandler.php]: Trong hàm loadmenu() xử lý gọi file menu1.php để hiển thị menu lên trang  Trong forder [includes] tạo file [menu1.php] Ví dụ code file menu1.php sau:  Trong forder [inlcudes] tạo file [menu.xml] code file menu.xml sau: o Dòng 55 file eventHandler.php: xử lý include file header.php thực thi hàm loadHeader()  Trong forder [includes] tạo file [header.php], code file header.php sau: o Dòng 58 file eventHandler.php: include file footer.php thực hàm loadFooter() Code file footer.php sau: - Cũng class admin class học viên chia phần xử lý form xử lý csdl riêng thành file Trong forder [QLTN2] tạo file xử lý csdl class môn hoc [MonHocDB.class.php] code sau: - Cách thức viết chức cho phần câu hỏi giống phần môn học Trong forder [QLTN2] tạo file [CauHoi.class.php] code sau: - Tiếp theo, forder [QLTN2] tạo file xử lý csdl class Câu hỏi [CauHoiDB.class.php] code sau:  Kết quả: http://localhost/QLTN2 ... file [header .php] , code file header .php sau: o Dòng 58 file eventHandler .php: include file footer .php thực hàm loadFooter() Code file footer .php sau: - Tiếp theo trở lại file default .php: inlcude... index .php include file TestManager.class .php o Trong file TestManager.class .php chia class sau: Admin.class .php HocVien.class .php MonHoc.class .php CauHoi.class .php Bây code class Admin class hocvien... TestManager.class .php code sau: ( Admin.class .php HocVien.class .php)     - - - Các chức inputAdmin(), outputAdmin(), setAdmin() trang index .php khai báo trang [TestManager.class .php] Trong hàm

Ngày đăng: 11/05/2018, 11:34

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan