Tải bản đầy đủ (.pdf) (11 trang)

Bài giảng Phát triển phần mềm mã nguồn mở: Zend framework

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.55 MB, 11 trang )

Zend Framework
Phát triển phần mềm mã nguồn mở


Zend Framework
1.
2.
3.
4.
5.

Thiết kế patterns
Thiết kế patterns theo MVC
Cấu trúc thư mục
Bootstrap
Ví dụ “Hello world”


Thiết kế patterns
Thiết kế pattern là giải pháp tái sử dụng cho
một vấn đề xảy ra thường xuyên trong thiết
kế phần mềm.
en.wikipedia.org/wiki/Design_pattern_(c
omputer_science))
(


Thiết kế patterns theo MVC
Model-View-Controller (MVC) là kiến trúc thiết kế
theo các lớp:
1. Model: Tầng logic nghiệp vụ của một ứng dụng


2. View: Tầng liên quan đến giao diện ứng dụng.
3. Controller: Tầng controller gắn kết mọi lớp lại với
nhau.


Cấu trúc thư mục


Bootstrap (index.php)


“Hello world” với ZF MVC
Vào đây:
application/controllers/IndexController.php
class IndexController extends Zend_Ctontroller_Action
{
public function indexAction()
{
}
}
?>


“Hello world”
Sau đó vào đây:
application/views/
Tạo file views/index/index.phtml
Và nội dung:
<html>

<body>
Hello world…………..
</body>
</html>


Tầng Models
Vào application/models
Viết thử
class Math
{
public function __construct()
{
}
public function sum($val1,$val2)
{
return $val1 + $val2;
}
}
?>


Tầng Model
Trong controller, gọi hàm sum lên
class IndexController extends Zend_Ctontroller Action
{
public function indexAction()
{

$math = new Math();
$sum = $math->sum(5,10);
$this->view->sum=$sum;
}
}
?>


Tiếp tục ví dụ
Cuối cùng trong tầng
view(application/view/scripts/index/index.ph
tml)
Viết mã,
echo ‘sum is ’ . $this->sum;
?>



×