2. Nội dung
1. Tạo
web
application
~
1
project
2. GET
/
POST
–
xử
lý
form
(xem
slide
sau)
3. Upload
file
(xem
slide
sau)
4. Tạo
web
service
(xem
slide
sau)
5. Đọc
ghi
cơ
sở
dữ
liệu
(xem
slide
sau)
http://techmaster.vn
3. Kỹ năng cần có
• Người
thuê
VPS
sẽ
tự
chịu
trách
nhiệm
quản
lý
tất
cả
các
web
site
từ
cài
đặt,
cấu
hình,
bảo
mật.
• Gõ
lệnh
trên
terminal.
Máy
chủ
ở
xa
thì
sẽ
phải
remote
SSH
vào
• Cheat
sheet:
– https://github.com/0nn0/terminal-‐mac-‐cheatsheet/wiki/Terminal-‐
Cheatsheet-‐for-‐Mac-‐(-‐basics-‐)
– http://i.imgur.com/1c9y0.png
– http://cli.learncodethehardway.org/bash_cheat_sheet.pdf
http://techmaster.vn
4. Các thư mục quan trọng
• /usr/local/var/www
là
nơi
chưa
các
thư
mục
gốc
• /usr/local/etc
chứa
các
file
cấu
hình
Nginx,
MySQL
• /usr/local/Cellar
chứa
ứng
dụng
cài
bởi
Home
Brew
• Một
VPS
có
thể
đồng
thời
host
được
nhiều
web
site,
http://techmaster.vn
5. Tạo một web application ~ 1 web site
có tên miền là paris.com
http://techmaster.vn
6. Tạo dự án có tên là paris.com == tền miền
cuong:www TechMaster$ cd /usr/local/var/www
cuong:www TechMaster$ phalcon project paris.com
Tạo
project
Phalcon DevTools (1.2.4)
Success: Controller "index" was successfully created.
Success: Project 'paris.com' was successfully created.
cuong:www TechMaster$ cd paris.com
cuong:paris.com TechMaster$ ls
app
index.html
public
cuong:paris.com TechMaster$
Chú
ý
2
thứ
mục
app,
public
http://techmaster.vn
7. cd /usr/local/etc/nginx
ls
nano nginx.conf
Nội
dung
file
nginx.conf
đơn
giản
tối
đa
Sửa
file
cấu
hình
nginx.conf
worker_processes 2;
events {
worker_connections 1024;
}
http {
include
mime.types;
default_type application/octet-stream;
sendfile
on;
tcp_nopush
on;
keepalive_timeout 65;
gzip on;
include conf.d/*.conf;
include sites-enabled/*;
}
http://techmaster.vn
8. Bạn cần cấu hình chi tiết cho từng site bên trong VPS
http://techmaster.vn
14. app
Chứa
code
viết
bằng
PHP,
Volt
app/cache
Chứa
file
PHP
được
render
từ
Volt
template,
Phacon
cần
có
quyền
write
thư
mục
này
app/config
Chứaconfig.php,
loader.php,
services.php
app/controllers
Các
controllers
hứng
các
request
từ
client
app/models
Các
models
ánh
xạ
với
các
bảng
trong
CSDL
app/views
Các
views
viết
bằng
Volt
public
Chứa
các
file
fnh
CSS,
JavaScript,
Images
http://techmaster.vn
17. Volt
is
an
ultra-‐fast
and
designer
friendly
templaQng
language
wriSen
in
C
for
PHP.
It
provides
you
a
set
of
helpers
to
write
views
in
an
easy
way.
Volt
is
highly
integrated
with
other
components
of
Phalcon,
just
as
you
can
use
it
as
a
stand-‐alone
component
in
your
applicaQons.
Volt Template
http://techmaster.vn
18. Controller à Views
<?php!
class IndexController extends ControllerBase!
{!
!
public function indexAction()!
{!
$this->view->name = "Cuong";!
}!
!
}!
<h1>Chào
mừng
<span
style="color:red">{{name}}</span>
đến
với
Phalcon</h1>
<div>
<img
src
="/img/phalcon.jpg"/>
</div>
http://techmaster.vn
19. How MVC App works
URL
Request
Taking
URL
request
then
sends
it
to
Dispatcher
Do
looping
to
select
the
appropriate
controller
and
acuon.
Phalcon/MVC/Router
Phalcon/MVC/Dispatcher
Loop
Controller
Display
responsing
data
Model
View
http://techmaster.vn
20. /usr/local/var/www/paris.com/app/views/index/index.volt
<h1>Chào
mừng
<span
style="color:red">{{name}}</span>
đến
với
Phalcon</h1>
<div>
<img
src
="/img/phalcon.jpg"/>
</div>
Phalcon
renders
Volt
template
/usr/local/var/www/paris.com/app/cache/_usr_local_var_www_paris.com_app_views_index_index.volt.php
<h1>Chào
mừng
<span
style="color:red"><?php
echo
$name;
?></span>
đến
với
Phalcon</h1>
<div>
<img
src
="/img/phalcon.jpg"/>
</div>
http://techmaster.vn
21. cd /usr/local/var/www/paris.com
phalcon controller signup
<?php!
!
class SignupController extends PhalconMvcController!
{!
public function indexAction()!
/app/controllers/SignupController.php
{!
!
}
!
}!
/app/views/signup/index.volt
<h1>Sign up form</h1>!
{{form('../signup/save', 'method': 'post')}}!
<label>Name</label>!
{{ text_field("name", "size": 32) }}!
<input type="text" name="job"/>!
{{ submit_button('Send') }}!
</form>!
http://techmaster.vn
22. <h1>Sign up form</h1>!
{{form('../signup/save', 'method': 'post')}}!
<label>Name</label>!
{{ text_field("name", "size": 32) }}!
<input type="text" name="job"/>!
{{ submit_button('Send') }}!
</form>!
public function saveAction()!
{!
echo ("Form is submitted!</br>");!
echo($this->request->getPost("name")."</br>");!
echo($this->request->getPost("job"));!
}!
http://techmaster.vn
23. Bây giờ là phần thực hành
http://techmaster.vn
24. Nếu
bạn
cần
phát
triển
ứng
dụng
web
trên
Phalcon
với
kinh
nghiệm
đội
phát
triển
cch
lũy
qua
nhiều
dự
án
mobile
–
web,
dynamic
responsive
web
quốc
tế
Tham
khảo
khóa
học
này
hSp://techmaster.vn/web/php-‐phalcon/
http://techmaster.vn