SlideShare a Scribd company logo
1 of 24
Phalcon PHP Framework
Căn bản

Trinh Minh Cuong, cuong@techmaster.vn

http://techmaster.vn
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
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
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
Tạo một web application ~ 1 web site
có tên miền là paris.com
http://techmaster.vn
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
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
Bạn cần cấu hình chi tiết cho từng site bên trong VPS

http://techmaster.vn
Chỉnh lại /etc/hosts
127.0.0.1
255.255.255.255
::1
fe80::1%lo0
127.0.0.1
127.0.0.1

localhost
broadcasthost
localhost
localhost
audiogara.com
paris.com	
  

Bổ	
  xung	
  entry	
  nào	
  

Đối	
  với	
  môi	
  trường	
  thật	
  cấu	
  hình	
  DNS	
  trỏ	
  tên	
  miền	
  paris.com	
  vào	
  địa	
  
chỉ	
  IP	
  Fnh	
  của	
  VPS	
  là	
  xong	
  !	
  

http://techmaster.vn
server {!
listen
80;!
index index.php index.html index.htm;!
set $root_path '/usr/local/var/www/paris.com/public';!
root $root_path;!
!
server_name paris.com;!
try_files $uri $uri/ @rewrite;!

Cấu	
  hình	
  thư	
  mục	
  
chứa	
  web	
  site	
  và	
  
tên	
  miền	
  

!
location @rewrite {!
rewrite ^/(.*)$ /index.php?_url=/$1;!
}!
location ~ .php {!
include fastcgi.conf;!
fastcgi_intercept_errors on;!
fastcgi_pass 127.0.0.1:9000;!
}!

Cấu	
  hình	
  PHP-­‐FPM	
  
parse	
  các	
  file	
  PHP	
  

!
location ~* ^/(css|img|js|flv|swf|download)/(.+) {!
root $root_path;!
}!
!
location ~ /.ht {!
deny all;!
}!
}!

http://techmaster.vn
Khi thay đổi nginx.conf và site.conf cần restart lại nginx

•  Bật	
  
sudo	
  nginx	
  

•  Tắt	
  
sudo	
  nginx	
  -­‐s	
  stop	
  

http://techmaster.vn
Volt directory can't be written

sudo chmod -R 777 /usr/local/var/www/paris.com/app/cache	
  

http://techmaster.vn
Lập trình Phalcon
http://techmaster.vn
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
/usr/local/var/www/paris.com/app/views/index.volt
<!DOCTYPE html>!
de	
  
<html>!
	
  Unico
nt
	
  trợ	
  fo
"<head>!
Hỗ
"
"<meta charset="UTF-8">!
"
"<title>Phalcon PHP Framework</title>!
"</head>!
"<body>!
"
"{{ content() }}!
"</body>!
</html>!

http://techmaster.vn
/usr/local/var/www/paris.com/app/views/index/index.volt
<h1>Chào	
  mừng	
  bạn	
  đến	
  với	
  Phalcon</h1>	
  
<div>	
  
<img	
  src	
  ="/img/phalcon.jpg"/>	
  
</div>	
  

http://techmaster.vn
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
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
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
/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
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
<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
Bây giờ là phần thực hành

http://techmaster.vn
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

More Related Content

What's hot

Go micro framework to build microservices
Go micro framework to build microservicesGo micro framework to build microservices
Go micro framework to build microservicesTechMaster Vietnam
 
Hướng dẫn cài đặt FW Laravel trên môi trường linux
Hướng dẫn cài đặt FW Laravel trên môi trường linuxHướng dẫn cài đặt FW Laravel trên môi trường linux
Hướng dẫn cài đặt FW Laravel trên môi trường linuxLe Thanh
 
Devwork.vn Tài liệu lập trình PHP Laravel
Devwork.vn Tài liệu lập trình PHP LaravelDevwork.vn Tài liệu lập trình PHP Laravel
Devwork.vn Tài liệu lập trình PHP LaravelDevwork
 
Phương pháp và chiến lược đối ứng tải trong Web Application Server
Phương pháp và chiến lược đối ứng tải trong Web Application ServerPhương pháp và chiến lược đối ứng tải trong Web Application Server
Phương pháp và chiến lược đối ứng tải trong Web Application ServerGMO-Z.com Vietnam Lab Center
 
Hướng dẫn cài đặt và cấu hình cacti trên cent os
Hướng dẫn cài đặt và cấu hình cacti trên cent osHướng dẫn cài đặt và cấu hình cacti trên cent os
Hướng dẫn cài đặt và cấu hình cacti trên cent oslaonap166
 
Nodejs Introduction
Nodejs IntroductionNodejs Introduction
Nodejs Introductionthanh can
 
It monitoring with nagios lac tien man thang
It monitoring with nagios lac tien man thangIt monitoring with nagios lac tien man thang
It monitoring with nagios lac tien man thanglaonap166
 
Báo cáo thực tập doanh nghiệp-Athena
Báo cáo thực tập doanh nghiệp-AthenaBáo cáo thực tập doanh nghiệp-Athena
Báo cáo thực tập doanh nghiệp-Athenaquocluong
 
Mysql Workbench hướng dẫn cài đặt - Video tiếng Việt
Mysql Workbench hướng dẫn cài đặt - Video tiếng ViệtMysql Workbench hướng dẫn cài đặt - Video tiếng Việt
Mysql Workbench hướng dẫn cài đặt - Video tiếng ViệtKhanhPham
 
Cách cài đặt localhost trên máy tính với xxamp
Cách cài đặt localhost trên máy tính với xxampCách cài đặt localhost trên máy tính với xxamp
Cách cài đặt localhost trên máy tính với xxampSon Nguyen
 

What's hot (20)

Go micro framework to build microservices
Go micro framework to build microservicesGo micro framework to build microservices
Go micro framework to build microservices
 
Hướng dẫn cài đặt FW Laravel trên môi trường linux
Hướng dẫn cài đặt FW Laravel trên môi trường linuxHướng dẫn cài đặt FW Laravel trên môi trường linux
Hướng dẫn cài đặt FW Laravel trên môi trường linux
 
Web301 slide 1
Web301   slide 1Web301   slide 1
Web301 slide 1
 
03 udpt php
03 udpt   php03 udpt   php
03 udpt php
 
Devwork.vn Tài liệu lập trình PHP Laravel
Devwork.vn Tài liệu lập trình PHP LaravelDevwork.vn Tài liệu lập trình PHP Laravel
Devwork.vn Tài liệu lập trình PHP Laravel
 
Laravel 5 framework
Laravel 5 frameworkLaravel 5 framework
Laravel 5 framework
 
Web203 slide 8
Web203   slide 8Web203   slide 8
Web203 slide 8
 
Phương pháp và chiến lược đối ứng tải trong Web Application Server
Phương pháp và chiến lược đối ứng tải trong Web Application ServerPhương pháp và chiến lược đối ứng tải trong Web Application Server
Phương pháp và chiến lược đối ứng tải trong Web Application Server
 
Web203 slide 5
Web203   slide 5Web203   slide 5
Web203 slide 5
 
Hướng dẫn cài đặt và cấu hình cacti trên cent os
Hướng dẫn cài đặt và cấu hình cacti trên cent osHướng dẫn cài đặt và cấu hình cacti trên cent os
Hướng dẫn cài đặt và cấu hình cacti trên cent os
 
Nodejs Introduction
Nodejs IntroductionNodejs Introduction
Nodejs Introduction
 
Giới thiệu Embulk
Giới thiệu Embulk Giới thiệu Embulk
Giới thiệu Embulk
 
Web301 slide 4
Web301   slide 4Web301   slide 4
Web301 slide 4
 
Web203 slide 4
Web203   slide 4Web203   slide 4
Web203 slide 4
 
It monitoring with nagios lac tien man thang
It monitoring with nagios lac tien man thangIt monitoring with nagios lac tien man thang
It monitoring with nagios lac tien man thang
 
Báo cáo thực tập doanh nghiệp-Athena
Báo cáo thực tập doanh nghiệp-AthenaBáo cáo thực tập doanh nghiệp-Athena
Báo cáo thực tập doanh nghiệp-Athena
 
Tìm hiểu về NodeJs
Tìm hiểu về NodeJsTìm hiểu về NodeJs
Tìm hiểu về NodeJs
 
Web203 slide 7
Web203   slide 7Web203   slide 7
Web203 slide 7
 
Mysql Workbench hướng dẫn cài đặt - Video tiếng Việt
Mysql Workbench hướng dẫn cài đặt - Video tiếng ViệtMysql Workbench hướng dẫn cài đặt - Video tiếng Việt
Mysql Workbench hướng dẫn cài đặt - Video tiếng Việt
 
Cách cài đặt localhost trên máy tính với xxamp
Cách cài đặt localhost trên máy tính với xxampCách cài đặt localhost trên máy tính với xxamp
Cách cài đặt localhost trên máy tính với xxamp
 

Viewers also liked

Prototyping giao diện sử dụng Expression Blend Sketch Flow
Prototyping giao diện sử dụng Expression Blend Sketch FlowPrototyping giao diện sử dụng Expression Blend Sketch Flow
Prototyping giao diện sử dụng Expression Blend Sketch FlowTechMaster Vietnam
 
Cấu hình Postgresql căn bản trong 20 phút
Cấu hình Postgresql căn bản trong 20 phútCấu hình Postgresql căn bản trong 20 phút
Cấu hình Postgresql căn bản trong 20 phútTechMaster Vietnam
 
Cơ sở dữ liệu postgres
Cơ sở dữ liệu postgresCơ sở dữ liệu postgres
Cơ sở dữ liệu postgresTechMaster Vietnam
 
Bài trình bày cho sinh viên Bách Khoa 9/2012
Bài trình bày cho sinh viên Bách Khoa 9/2012Bài trình bày cho sinh viên Bách Khoa 9/2012
Bài trình bày cho sinh viên Bách Khoa 9/2012TechMaster Vietnam
 

Viewers also liked (10)

Phalcon overview
Phalcon overviewPhalcon overview
Phalcon overview
 
Making a living
Making a livingMaking a living
Making a living
 
Prototyping giao diện sử dụng Expression Blend Sketch Flow
Prototyping giao diện sử dụng Expression Blend Sketch FlowPrototyping giao diện sử dụng Expression Blend Sketch Flow
Prototyping giao diện sử dụng Expression Blend Sketch Flow
 
Postgresql security
Postgresql securityPostgresql security
Postgresql security
 
iOS Master - Detail & TabBar
iOS Master - Detail & TabBariOS Master - Detail & TabBar
iOS Master - Detail & TabBar
 
Minimum Viable Products
Minimum Viable ProductsMinimum Viable Products
Minimum Viable Products
 
Cấu hình Postgresql căn bản trong 20 phút
Cấu hình Postgresql căn bản trong 20 phútCấu hình Postgresql căn bản trong 20 phút
Cấu hình Postgresql căn bản trong 20 phút
 
Cơ sở dữ liệu postgres
Cơ sở dữ liệu postgresCơ sở dữ liệu postgres
Cơ sở dữ liệu postgres
 
Slide that wins
Slide that winsSlide that wins
Slide that wins
 
Bài trình bày cho sinh viên Bách Khoa 9/2012
Bài trình bày cho sinh viên Bách Khoa 9/2012Bài trình bày cho sinh viên Bách Khoa 9/2012
Bài trình bày cho sinh viên Bách Khoa 9/2012
 

Similar to Phalcon căn bản

Technical note playframework_documentation_working with play - java_vn
Technical note playframework_documentation_working with play - java_vnTechnical note playframework_documentation_working with play - java_vn
Technical note playframework_documentation_working with play - java_vnAsahina Infotech
 
Huong dan cau hinh fortigate
Huong dan cau hinh fortigateHuong dan cau hinh fortigate
Huong dan cau hinh fortigatenggianglx
 
Hướng dẫn cấu hình monitor vmware es xi host dùng cacti
Hướng dẫn cấu hình monitor vmware es xi host dùng cactiHướng dẫn cấu hình monitor vmware es xi host dùng cacti
Hướng dẫn cấu hình monitor vmware es xi host dùng cactilaonap166
 
Devexpress cho asp.net
Devexpress cho asp.netDevexpress cho asp.net
Devexpress cho asp.netthichxoidau
 
Báo cáo thực tập tuần 7 - 8 tại athena - đàm văn sáng
Báo cáo thực tập tuần 7 - 8 tại athena - đàm văn sángBáo cáo thực tập tuần 7 - 8 tại athena - đàm văn sáng
Báo cáo thực tập tuần 7 - 8 tại athena - đàm văn sángĐàm Văn Sáng
 
Run Openstack with SSL
Run Openstack with SSLRun Openstack with SSL
Run Openstack with SSLLam To
 
Linux thietlaphethongmangubunt-45879
Linux thietlaphethongmangubunt-45879Linux thietlaphethongmangubunt-45879
Linux thietlaphethongmangubunt-45879Son Giap
 
Cai dat squid proxy trong suot
Cai dat  squid proxy trong suotCai dat  squid proxy trong suot
Cai dat squid proxy trong suotTHT
 
Báo cáo thực tập trần trọng thái
Báo cáo thực tập   trần trọng tháiBáo cáo thực tập   trần trọng thái
Báo cáo thực tập trần trọng tháitran thai
 
php với oracle database
php với oracle databasephp với oracle database
php với oracle databaseNgo Trung
 
Trần Anh Khoa - Kautilya và Powershell trong kỹ thuật tấn công tiếp cận
Trần Anh Khoa - Kautilya và Powershelltrong kỹ thuật tấn công tiếp cậnTrần Anh Khoa - Kautilya và Powershelltrong kỹ thuật tấn công tiếp cận
Trần Anh Khoa - Kautilya và Powershell trong kỹ thuật tấn công tiếp cậnSecurity Bootcamp
 
Slide py-sys-devops-final-v1
Slide py-sys-devops-final-v1Slide py-sys-devops-final-v1
Slide py-sys-devops-final-v1Công TÔ
 
Bài 1 Lập trình website theo mô hình MVC - Xây dựng ứng dụng web
Bài 1 Lập trình website theo mô hình MVC - Xây dựng ứng dụng webBài 1 Lập trình website theo mô hình MVC - Xây dựng ứng dụng web
Bài 1 Lập trình website theo mô hình MVC - Xây dựng ứng dụng webMasterCode.vn
 
đề thi trắc nghiệm asp net co kem đáp án trên 400 câu hỏi thiết kế website ki...
đề thi trắc nghiệm asp net co kem đáp án trên 400 câu hỏi thiết kế website ki...đề thi trắc nghiệm asp net co kem đáp án trên 400 câu hỏi thiết kế website ki...
đề thi trắc nghiệm asp net co kem đáp án trên 400 câu hỏi thiết kế website ki...anh hieu
 
Scop full realtime solutions yeucau mohinh_tiendo setup bbb
Scop full realtime solutions yeucau mohinh_tiendo setup bbbScop full realtime solutions yeucau mohinh_tiendo setup bbb
Scop full realtime solutions yeucau mohinh_tiendo setup bbblaonap166
 
HƯỚNG DẪN SỬ DỤNG PHẦN MỀM SUBVERSION (SVN) TOÀN TẬP
HƯỚNG DẪN SỬ DỤNG PHẦN MỀM SUBVERSION (SVN) TOÀN TẬPHƯỚNG DẪN SỬ DỤNG PHẦN MỀM SUBVERSION (SVN) TOÀN TẬP
HƯỚNG DẪN SỬ DỤNG PHẦN MỀM SUBVERSION (SVN) TOÀN TẬPdvms
 

Similar to Phalcon căn bản (20)

Technical note playframework_documentation_working with play - java_vn
Technical note playframework_documentation_working with play - java_vnTechnical note playframework_documentation_working with play - java_vn
Technical note playframework_documentation_working with play - java_vn
 
Huong dan cau hinh fortigate
Huong dan cau hinh fortigateHuong dan cau hinh fortigate
Huong dan cau hinh fortigate
 
Tailieu
TailieuTailieu
Tailieu
 
Hướng dẫn cấu hình monitor vmware es xi host dùng cacti
Hướng dẫn cấu hình monitor vmware es xi host dùng cactiHướng dẫn cấu hình monitor vmware es xi host dùng cacti
Hướng dẫn cấu hình monitor vmware es xi host dùng cacti
 
Devexpress cho asp.net
Devexpress cho asp.netDevexpress cho asp.net
Devexpress cho asp.net
 
Báo cáo thực tập tuần 7 - 8 tại athena - đàm văn sáng
Báo cáo thực tập tuần 7 - 8 tại athena - đàm văn sángBáo cáo thực tập tuần 7 - 8 tại athena - đàm văn sáng
Báo cáo thực tập tuần 7 - 8 tại athena - đàm văn sáng
 
Run Openstack with SSL
Run Openstack with SSLRun Openstack with SSL
Run Openstack with SSL
 
Linux thietlaphethongmangubunt-45879
Linux thietlaphethongmangubunt-45879Linux thietlaphethongmangubunt-45879
Linux thietlaphethongmangubunt-45879
 
Cai dat squid proxy trong suot
Cai dat  squid proxy trong suotCai dat  squid proxy trong suot
Cai dat squid proxy trong suot
 
Báo cáo thực tập trần trọng thái
Báo cáo thực tập   trần trọng tháiBáo cáo thực tập   trần trọng thái
Báo cáo thực tập trần trọng thái
 
php với oracle database
php với oracle databasephp với oracle database
php với oracle database
 
Báo cáo tuần đồ án
Báo cáo tuần đồ ánBáo cáo tuần đồ án
Báo cáo tuần đồ án
 
Trần Anh Khoa - Kautilya và Powershell trong kỹ thuật tấn công tiếp cận
Trần Anh Khoa - Kautilya và Powershelltrong kỹ thuật tấn công tiếp cậnTrần Anh Khoa - Kautilya và Powershelltrong kỹ thuật tấn công tiếp cận
Trần Anh Khoa - Kautilya và Powershell trong kỹ thuật tấn công tiếp cận
 
Slide py-sys-devops-final-v1
Slide py-sys-devops-final-v1Slide py-sys-devops-final-v1
Slide py-sys-devops-final-v1
 
Bài 1 Lập trình website theo mô hình MVC - Xây dựng ứng dụng web
Bài 1 Lập trình website theo mô hình MVC - Xây dựng ứng dụng webBài 1 Lập trình website theo mô hình MVC - Xây dựng ứng dụng web
Bài 1 Lập trình website theo mô hình MVC - Xây dựng ứng dụng web
 
400 câu hỏi thi trắc nghiệm ASP.NET có đáp án - Thiết kế website kinh doanh 2
400 câu hỏi thi trắc nghiệm ASP.NET có đáp án - Thiết kế website kinh doanh 2400 câu hỏi thi trắc nghiệm ASP.NET có đáp án - Thiết kế website kinh doanh 2
400 câu hỏi thi trắc nghiệm ASP.NET có đáp án - Thiết kế website kinh doanh 2
 
đề thi trắc nghiệm asp net co kem đáp án trên 400 câu hỏi thiết kế website ki...
đề thi trắc nghiệm asp net co kem đáp án trên 400 câu hỏi thiết kế website ki...đề thi trắc nghiệm asp net co kem đáp án trên 400 câu hỏi thiết kế website ki...
đề thi trắc nghiệm asp net co kem đáp án trên 400 câu hỏi thiết kế website ki...
 
Scop full realtime solutions yeucau mohinh_tiendo setup bbb
Scop full realtime solutions yeucau mohinh_tiendo setup bbbScop full realtime solutions yeucau mohinh_tiendo setup bbb
Scop full realtime solutions yeucau mohinh_tiendo setup bbb
 
HƯỚNG DẪN SỬ DỤNG PHẦN MỀM SUBVERSION (SVN) TOÀN TẬP
HƯỚNG DẪN SỬ DỤNG PHẦN MỀM SUBVERSION (SVN) TOÀN TẬPHƯỚNG DẪN SỬ DỤNG PHẦN MỀM SUBVERSION (SVN) TOÀN TẬP
HƯỚNG DẪN SỬ DỤNG PHẦN MỀM SUBVERSION (SVN) TOÀN TẬP
 
Asp control
Asp controlAsp control
Asp control
 

More from TechMaster Vietnam

Chia sẻ kinh nghiệm giảng dạy CNTT
Chia sẻ kinh nghiệm giảng dạy CNTTChia sẻ kinh nghiệm giảng dạy CNTT
Chia sẻ kinh nghiệm giảng dạy CNTTTechMaster Vietnam
 
Manage your project differently
Manage your project differentlyManage your project differently
Manage your project differentlyTechMaster Vietnam
 
Chương trình thực tập chuyên sâu dành cho học viên khóa iOS tại TechMaster
Chương trình thực tập chuyên sâu dành cho học viên khóa iOS tại TechMasterChương trình thực tập chuyên sâu dành cho học viên khóa iOS tại TechMaster
Chương trình thực tập chuyên sâu dành cho học viên khóa iOS tại TechMasterTechMaster Vietnam
 
Apple iOS Memory Management - Vietnamese version
Apple iOS Memory Management - Vietnamese versionApple iOS Memory Management - Vietnamese version
Apple iOS Memory Management - Vietnamese versionTechMaster Vietnam
 
Sinh viên CNTT làm gì trong 5 năm tới
Sinh viên CNTT làm gì trong 5 năm tớiSinh viên CNTT làm gì trong 5 năm tới
Sinh viên CNTT làm gì trong 5 năm tớiTechMaster Vietnam
 

More from TechMaster Vietnam (12)

Neural Network from Scratch
Neural Network from ScratchNeural Network from Scratch
Neural Network from Scratch
 
Flutter vs React Native 2018
Flutter vs React Native 2018Flutter vs React Native 2018
Flutter vs React Native 2018
 
C đến C++ phần 1
C đến C++ phần 1C đến C++ phần 1
C đến C++ phần 1
 
Control structure in C
Control structure in CControl structure in C
Control structure in C
 
Basic C programming
Basic C programmingBasic C programming
Basic C programming
 
Knex Postgresql Migration
Knex Postgresql MigrationKnex Postgresql Migration
Knex Postgresql Migration
 
Chia sẻ kinh nghiệm giảng dạy CNTT
Chia sẻ kinh nghiệm giảng dạy CNTTChia sẻ kinh nghiệm giảng dạy CNTT
Chia sẻ kinh nghiệm giảng dạy CNTT
 
Manage your project differently
Manage your project differentlyManage your project differently
Manage your project differently
 
Chương trình thực tập chuyên sâu dành cho học viên khóa iOS tại TechMaster
Chương trình thực tập chuyên sâu dành cho học viên khóa iOS tại TechMasterChương trình thực tập chuyên sâu dành cho học viên khóa iOS tại TechMaster
Chương trình thực tập chuyên sâu dành cho học viên khóa iOS tại TechMaster
 
Apple iOS Memory Management - Vietnamese version
Apple iOS Memory Management - Vietnamese versionApple iOS Memory Management - Vietnamese version
Apple iOS Memory Management - Vietnamese version
 
Sinh viên CNTT làm gì trong 5 năm tới
Sinh viên CNTT làm gì trong 5 năm tớiSinh viên CNTT làm gì trong 5 năm tới
Sinh viên CNTT làm gì trong 5 năm tới
 
Windows 8 vs android 4
Windows 8 vs android 4Windows 8 vs android 4
Windows 8 vs android 4
 

Phalcon căn bản

  • 1. Phalcon PHP Framework Căn bản Trinh Minh Cuong, cuong@techmaster.vn http://techmaster.vn
  • 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
  • 9. Chỉnh lại /etc/hosts 127.0.0.1 255.255.255.255 ::1 fe80::1%lo0 127.0.0.1 127.0.0.1 localhost broadcasthost localhost localhost audiogara.com paris.com   Bổ  xung  entry  nào   Đối  với  môi  trường  thật  cấu  hình  DNS  trỏ  tên  miền  paris.com  vào  địa   chỉ  IP  Fnh  của  VPS  là  xong  !   http://techmaster.vn
  • 10. server {! listen 80;! index index.php index.html index.htm;! set $root_path '/usr/local/var/www/paris.com/public';! root $root_path;! ! server_name paris.com;! try_files $uri $uri/ @rewrite;! Cấu  hình  thư  mục   chứa  web  site  và   tên  miền   ! location @rewrite {! rewrite ^/(.*)$ /index.php?_url=/$1;! }! location ~ .php {! include fastcgi.conf;! fastcgi_intercept_errors on;! fastcgi_pass 127.0.0.1:9000;! }! Cấu  hình  PHP-­‐FPM   parse  các  file  PHP   ! location ~* ^/(css|img|js|flv|swf|download)/(.+) {! root $root_path;! }! ! location ~ /.ht {! deny all;! }! }! http://techmaster.vn
  • 11. Khi thay đổi nginx.conf và site.conf cần restart lại nginx •  Bật   sudo  nginx   •  Tắt   sudo  nginx  -­‐s  stop   http://techmaster.vn
  • 12. Volt directory can't be written sudo chmod -R 777 /usr/local/var/www/paris.com/app/cache   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
  • 15. /usr/local/var/www/paris.com/app/views/index.volt <!DOCTYPE html>! de   <html>!  Unico nt  trợ  fo "<head>! Hỗ " "<meta charset="UTF-8">! " "<title>Phalcon PHP Framework</title>! "</head>! "<body>! " "{{ content() }}! "</body>! </html>! http://techmaster.vn
  • 16. /usr/local/var/www/paris.com/app/views/index/index.volt <h1>Chào  mừng  bạn  đến  với  Phalcon</h1>   <div>   <img  src  ="/img/phalcon.jpg"/>   </div>   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