SlideShare uma empresa Scribd logo
1 de 41
行動APP開發管理實務
WNMP & Phalcon Micro App – Part II
2016.01.05 @ 淡江大學商管B217
Taien Wang <taien_wang@hiiir.com>
時間軸科技股份有限公司
Agenda
• Part I
– Windows
• nginx
• php
• Phalcon
• Part II
– mysql
– micro-restful api
2
Review
• Resource: http://taien.idv.tw/files/20160105-tku-web.7z
– nginx
– php
– phalcon
3
Phalcon
• Download Phalcon form https://phalconphp.com/en/download/windows
• Copy php_phalcon.dll to php extension dir
– ex: C:webphpext
• Modify the configuration from php.ini-development to php.ini
– extension=php_phalcon.dll
• Phalcon Dev Tool
– Download: https://phalconphp.com/en/download/tools
– Docs: https://docs.phalconphp.com/en/latest/reference/tools.html
– Source: https://github.com/phalcon/phalcon-devtools
4
Phalcon – Nginx configuration
5
source: https://docs.phalconphp.com/en/latest/reference/nginx.html
Target - AddressBook
API resource Method Raw Body
select a contact addressbook/{Id} GET
select multi contacts addressbook GET
create contact addressbook POST {"name":"taien","mobile":"0912111
111"}
modify contact addressbook/{Id} PUT {"name":"taien","mobile":"0912111
111"}
delete contact addressbook/{Id} DELETE
6
URL:http://tku.api.taien.idv.tw:8080/
Chrome extension - Postman
7
MySQL
• Download PHP form https://dev.mysql.com/downloads/mysql/
– mysql-installer-community-5.6.28.0.msi
8
MySQL – License agreement
9
MySQL – Choosing a setup type
10
MySQL – Select products and features
11
MySQL – Check requirements
12
MySQL – Installation excute
13
MySQL – Install complete
14
MySQL – Product configuration
15
MySQL – Type and networking
16
MySQL – Accounts and roles
17
MySQL – Window service
18
MySQL – Advanced options
19
MySQL – Apply server configuration
20
MySQL – Apply server configuration finish
21
MySQL – Product configuration
22
MySQL – Installation complete
23
MySQL – Create databases
• mysql –h localhost –u root –p
• CREATE DATABASE `tku-sample` CHARACTER SET utf8 COLLATE utf8_general_ci;
• use `tku-sample`;
• CREATE TABLE `addressbook` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
`mobile` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
24
Windows Environment Variables
• Environment Variables
– Path
• C:webphp;C:webnginx;C:webphalcon-devtools-master;C:Program
FilesMySQLMySQL Server 5.7bin
25
Phalcon Micro App Command
• Create project
– phalcon project tku --type=mirco
• Setup DB in config/config.php
• Create ORM model
– phalcon model addressbook
26
Restful API (1/3)
27
Restful API (2/3)
28
Restful API (3/3)
29
Phalcon Code - Hello TKU
$app->get('/tku', function () use ($app) {
echo "Hello, TKU!";
});
30
Phalcon Code - Select a contact
$app->get('/addressbook/{addressbookId}', function ($addressbookId) use ($app) {
$response = new Response();
$AddressBook = Addressbook::findFirst($addressbookId);
$data = array();
if ($AddressBook) {
$data["id"] = $AddressBook->id;
$data["name"] = $AddressBook->name;
$data["mobile"] = $AddressBook->mobile;
echo json_encode($data);
} else {
$response->setStatusCode(404, "Not Found");
return $response;
}});
31
Phalcon Code - Select multi contacts
$app->get('/addressbook', function () use ($app) {
$AddressBooks = Addressbook::find();
$data = array();
foreach ($AddressBooks as $AddressBook) {
$data[] = array(
'id' => $AddressBook->id,
'name' => $AddressBook->name,
'mobile' => $AddressBook->mobile);
}
echo json_encode($data);
});
32
Phalcon Code - Create contact
$app->post('/addressbook', function () use ($app) {
$response = new Response();
$bodyData = $app->request->getJsonRawBody();
$requestAry = json_decode(json_encode($bodyData), true);
$AddressBook = new Addressbook;
$AddressBook->name = $requestAry["name"];
$AddressBook->mobile = $requestAry["mobile"];
$result = $AddressBook->save();
if ($result) {
$response->setStatusCode(201, "Created");
} else {
$response->setStatusCode(500, "Internal Error");
}
return $response;
});
33
Phalcon Code - Modify contact
$app->put('/addressbook/{addressbookId}', function ($addressbookId) use ($app) {
$response = new Response();
$bodyData = $app->request->getJsonRawBody();
$requestAry = json_decode(json_encode($bodyData), true);
$AddressBook = Addressbook::findFirst($addressbookId);
if ($AddressBook) {
$AddressBook->name = $requestAry["name"];
$AddressBook->mobile = $requestAry["mobile"];
$result = $AddressBook->save();
if ($result) {
$response->setStatusCode(202, "Accepted");
} else {
$response->setStatusCode(500, "Internal Error");
}
} else {
$response->setStatusCode(500, "Internal Error");
}
return $response;
});
34
Phalcon Code - Delete contact
$app->delete('/addressbook/{addressbookId}', function ($addressbookId) use ($app) {
$response = new Response();
$AddressBook = Addressbook::findFirst($addressbookId);
if ($AddressBook) {
$result = $AddressBook->delete();
if ($result) {
$response->setStatusCode(202, "Accepted");
} else {
$response->setStatusCode(500, "Internal Error");
}
} else {
$response->setStatusCode(500, "Internal Error");
}
return $response;
});
35
Mission
• 20%: Select a contact
• 20%: Select multi contact
• 20%: Create a contact
• 20%: Modify a contact
• 20%: Delete a contact
36
Mission - Select multi contact
37
Mission - Select a contact
38
Mission - Create a contact
39
Mission – Modify a contact
40
Mission – Delete a contact
41

Mais conteúdo relacionado

Mais procurados

Awash in a sea of connections
Awash in a sea of connectionsAwash in a sea of connections
Awash in a sea of connections
Galen Charlton
 

Mais procurados (7)

Laravel でやってみるクリーンアーキテクチャ #phpconfuk
Laravel でやってみるクリーンアーキテクチャ #phpconfukLaravel でやってみるクリーンアーキテクチャ #phpconfuk
Laravel でやってみるクリーンアーキテクチャ #phpconfuk
 
Awash in a sea of connections
Awash in a sea of connectionsAwash in a sea of connections
Awash in a sea of connections
 
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For KohaPutting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
 
Web Scraping
Web ScrapingWeb Scraping
Web Scraping
 
YAP / Open Mail Overview
YAP / Open Mail OverviewYAP / Open Mail Overview
YAP / Open Mail Overview
 
TDC2015 Porto Alegre - Automate everything with Phing !
TDC2015 Porto Alegre - Automate everything with Phing !TDC2015 Porto Alegre - Automate everything with Phing !
TDC2015 Porto Alegre - Automate everything with Phing !
 
Reactive computing
Reactive computingReactive computing
Reactive computing
 

Semelhante a 20160105 wnmp & phalcon micro app - part II

HotPush with Ionic 2 and CodePush
HotPush with Ionic 2 and CodePushHotPush with Ionic 2 and CodePush
HotPush with Ionic 2 and CodePush
Evan Schultz
 
Jakob Holderbaum - Managing Shared secrets using basic Unix tools
Jakob Holderbaum - Managing Shared secrets using basic Unix toolsJakob Holderbaum - Managing Shared secrets using basic Unix tools
Jakob Holderbaum - Managing Shared secrets using basic Unix tools
DevSecCon
 

Semelhante a 20160105 wnmp & phalcon micro app - part II (20)

fb-researchの舞台裏No.2~技術編~(HatchUp主催 渋谷Facebookアプリ勉強会)
fb-researchの舞台裏No.2~技術編~(HatchUp主催 渋谷Facebookアプリ勉強会)fb-researchの舞台裏No.2~技術編~(HatchUp主催 渋谷Facebookアプリ勉強会)
fb-researchの舞台裏No.2~技術編~(HatchUp主催 渋谷Facebookアプリ勉強会)
 
Kyiv.py #17 Flask talk
Kyiv.py #17 Flask talkKyiv.py #17 Flask talk
Kyiv.py #17 Flask talk
 
Building Cloud Castles
Building Cloud CastlesBuilding Cloud Castles
Building Cloud Castles
 
Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web Artisans
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
Collaboration hack with slackbot - PyCon HK 2018 - 2018.11.24
Collaboration hack with slackbot - PyCon HK 2018 - 2018.11.24Collaboration hack with slackbot - PyCon HK 2018 - 2018.11.24
Collaboration hack with slackbot - PyCon HK 2018 - 2018.11.24
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2
 
Symfony console: build awesome command line scripts with ease
Symfony console: build awesome command line scripts with easeSymfony console: build awesome command line scripts with ease
Symfony console: build awesome command line scripts with ease
 
Ecto and Phoenix: Doing web with Elixir - Yurii Bodarev
Ecto and Phoenix: Doing web with Elixir - Yurii BodarevEcto and Phoenix: Doing web with Elixir - Yurii Bodarev
Ecto and Phoenix: Doing web with Elixir - Yurii Bodarev
 
Ecto and Phoenix: Doing Web With Elixir
Ecto and Phoenix: Doing Web With ElixirEcto and Phoenix: Doing Web With Elixir
Ecto and Phoenix: Doing Web With Elixir
 
LvivPy - Flask in details
LvivPy - Flask in detailsLvivPy - Flask in details
LvivPy - Flask in details
 
HotPush with Ionic 2 and CodePush
HotPush with Ionic 2 and CodePushHotPush with Ionic 2 and CodePush
HotPush with Ionic 2 and CodePush
 
Jakob Holderbaum - Managing Shared secrets using basic Unix tools
Jakob Holderbaum - Managing Shared secrets using basic Unix toolsJakob Holderbaum - Managing Shared secrets using basic Unix tools
Jakob Holderbaum - Managing Shared secrets using basic Unix tools
 
TYPO3 Scheduler
TYPO3 SchedulerTYPO3 Scheduler
TYPO3 Scheduler
 
Pluggin creation
Pluggin creationPluggin creation
Pluggin creation
 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
 
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
 
Migrating data to drupal 8
Migrating data to drupal 8Migrating data to drupal 8
Migrating data to drupal 8
 

Mais de Taien Wang

伺服器端攻擊與防禦III
伺服器端攻擊與防禦III伺服器端攻擊與防禦III
伺服器端攻擊與防禦III
Taien Wang
 

Mais de Taien Wang (20)

[MOPCON2019]從零建立商業技術團隊
[MOPCON2019]從零建立商業技術團隊[MOPCON2019]從零建立商業技術團隊
[MOPCON2019]從零建立商業技術團隊
 
[ModernWeb2019] Taien - 高併發的道與術
[ModernWeb2019] Taien - 高併發的道與術[ModernWeb2019] Taien - 高併發的道與術
[ModernWeb2019] Taien - 高併發的道與術
 
[ModernWeb2018] Web3.0 區塊鏈 DApp + 智能合約開發:你必要挑戰的坑坑洞洞
[ModernWeb2018] Web3.0 區塊鏈 DApp + 智能合約開發:你必要挑戰的坑坑洞洞[ModernWeb2018] Web3.0 區塊鏈 DApp + 智能合約開發:你必要挑戰的坑坑洞洞
[ModernWeb2018] Web3.0 區塊鏈 DApp + 智能合約開發:你必要挑戰的坑坑洞洞
 
百人團隊敏捷轉型暨持續性整合與交付實踐
百人團隊敏捷轉型暨持續性整合與交付實踐百人團隊敏捷轉型暨持續性整合與交付實踐
百人團隊敏捷轉型暨持續性整合與交付實踐
 
淡江Git與GitHub操作介紹
淡江Git與GitHub操作介紹淡江Git與GitHub操作介紹
淡江Git與GitHub操作介紹
 
成長駭客 Growth Hacker
成長駭客 Growth Hacker成長駭客 Growth Hacker
成長駭客 Growth Hacker
 
20151229 wnmp & phalcon micro app - part I
20151229 wnmp & phalcon micro app - part I20151229 wnmp & phalcon micro app - part I
20151229 wnmp & phalcon micro app - part I
 
我編程.我快樂
我編程.我快樂我編程.我快樂
我編程.我快樂
 
Scrum深入淺出
Scrum深入淺出Scrum深入淺出
Scrum深入淺出
 
淡江大學 - 產品測試+安全性測試+壓力測試
淡江大學 - 產品測試+安全性測試+壓力測試淡江大學 - 產品測試+安全性測試+壓力測試
淡江大學 - 產品測試+安全性測試+壓力測試
 
淡江大學 - ios+android+html5(javascript)
淡江大學 - ios+android+html5(javascript)淡江大學 - ios+android+html5(javascript)
淡江大學 - ios+android+html5(javascript)
 
淡江大學 - 網站開發應用技術及雲端應用技術
淡江大學 - 網站開發應用技術及雲端應用技術淡江大學 - 網站開發應用技術及雲端應用技術
淡江大學 - 網站開發應用技術及雲端應用技術
 
Android Taipei 2013 August - Android Apps Security
Android Taipei 2013 August - Android Apps SecurityAndroid Taipei 2013 August - Android Apps Security
Android Taipei 2013 August - Android Apps Security
 
伺服器端攻擊與防禦III
伺服器端攻擊與防禦III伺服器端攻擊與防禦III
伺服器端攻擊與防禦III
 
伺服器端攻擊與防禦II
伺服器端攻擊與防禦II伺服器端攻擊與防禦II
伺服器端攻擊與防禦II
 
伺服器端攻擊與防禦I
伺服器端攻擊與防禦I伺服器端攻擊與防禦I
伺服器端攻擊與防禦I
 
用戶端攻擊與防禦
用戶端攻擊與防禦用戶端攻擊與防禦
用戶端攻擊與防禦
 
使安全成為軟體開發必要部分
使安全成為軟體開發必要部分使安全成為軟體開發必要部分
使安全成為軟體開發必要部分
 
基礎網頁程式攻擊檢驗
基礎網頁程式攻擊檢驗基礎網頁程式攻擊檢驗
基礎網頁程式攻擊檢驗
 
PHP更有效率的除錯 - XDebug
PHP更有效率的除錯 - XDebugPHP更有效率的除錯 - XDebug
PHP更有效率的除錯 - XDebug
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

20160105 wnmp & phalcon micro app - part II

  • 1. 行動APP開發管理實務 WNMP & Phalcon Micro App – Part II 2016.01.05 @ 淡江大學商管B217 Taien Wang <taien_wang@hiiir.com> 時間軸科技股份有限公司
  • 2. Agenda • Part I – Windows • nginx • php • Phalcon • Part II – mysql – micro-restful api 2
  • 4. Phalcon • Download Phalcon form https://phalconphp.com/en/download/windows • Copy php_phalcon.dll to php extension dir – ex: C:webphpext • Modify the configuration from php.ini-development to php.ini – extension=php_phalcon.dll • Phalcon Dev Tool – Download: https://phalconphp.com/en/download/tools – Docs: https://docs.phalconphp.com/en/latest/reference/tools.html – Source: https://github.com/phalcon/phalcon-devtools 4
  • 5. Phalcon – Nginx configuration 5 source: https://docs.phalconphp.com/en/latest/reference/nginx.html
  • 6. Target - AddressBook API resource Method Raw Body select a contact addressbook/{Id} GET select multi contacts addressbook GET create contact addressbook POST {"name":"taien","mobile":"0912111 111"} modify contact addressbook/{Id} PUT {"name":"taien","mobile":"0912111 111"} delete contact addressbook/{Id} DELETE 6 URL:http://tku.api.taien.idv.tw:8080/
  • 7. Chrome extension - Postman 7
  • 8. MySQL • Download PHP form https://dev.mysql.com/downloads/mysql/ – mysql-installer-community-5.6.28.0.msi 8
  • 9. MySQL – License agreement 9
  • 10. MySQL – Choosing a setup type 10
  • 11. MySQL – Select products and features 11
  • 12. MySQL – Check requirements 12
  • 14. MySQL – Install complete 14
  • 15. MySQL – Product configuration 15
  • 16. MySQL – Type and networking 16
  • 17. MySQL – Accounts and roles 17
  • 18. MySQL – Window service 18
  • 19. MySQL – Advanced options 19
  • 20. MySQL – Apply server configuration 20
  • 21. MySQL – Apply server configuration finish 21
  • 22. MySQL – Product configuration 22
  • 23. MySQL – Installation complete 23
  • 24. MySQL – Create databases • mysql –h localhost –u root –p • CREATE DATABASE `tku-sample` CHARACTER SET utf8 COLLATE utf8_general_ci; • use `tku-sample`; • CREATE TABLE `addressbook` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(45) NOT NULL, `mobile` varchar(45) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; 24
  • 25. Windows Environment Variables • Environment Variables – Path • C:webphp;C:webnginx;C:webphalcon-devtools-master;C:Program FilesMySQLMySQL Server 5.7bin 25
  • 26. Phalcon Micro App Command • Create project – phalcon project tku --type=mirco • Setup DB in config/config.php • Create ORM model – phalcon model addressbook 26
  • 30. Phalcon Code - Hello TKU $app->get('/tku', function () use ($app) { echo "Hello, TKU!"; }); 30
  • 31. Phalcon Code - Select a contact $app->get('/addressbook/{addressbookId}', function ($addressbookId) use ($app) { $response = new Response(); $AddressBook = Addressbook::findFirst($addressbookId); $data = array(); if ($AddressBook) { $data["id"] = $AddressBook->id; $data["name"] = $AddressBook->name; $data["mobile"] = $AddressBook->mobile; echo json_encode($data); } else { $response->setStatusCode(404, "Not Found"); return $response; }}); 31
  • 32. Phalcon Code - Select multi contacts $app->get('/addressbook', function () use ($app) { $AddressBooks = Addressbook::find(); $data = array(); foreach ($AddressBooks as $AddressBook) { $data[] = array( 'id' => $AddressBook->id, 'name' => $AddressBook->name, 'mobile' => $AddressBook->mobile); } echo json_encode($data); }); 32
  • 33. Phalcon Code - Create contact $app->post('/addressbook', function () use ($app) { $response = new Response(); $bodyData = $app->request->getJsonRawBody(); $requestAry = json_decode(json_encode($bodyData), true); $AddressBook = new Addressbook; $AddressBook->name = $requestAry["name"]; $AddressBook->mobile = $requestAry["mobile"]; $result = $AddressBook->save(); if ($result) { $response->setStatusCode(201, "Created"); } else { $response->setStatusCode(500, "Internal Error"); } return $response; }); 33
  • 34. Phalcon Code - Modify contact $app->put('/addressbook/{addressbookId}', function ($addressbookId) use ($app) { $response = new Response(); $bodyData = $app->request->getJsonRawBody(); $requestAry = json_decode(json_encode($bodyData), true); $AddressBook = Addressbook::findFirst($addressbookId); if ($AddressBook) { $AddressBook->name = $requestAry["name"]; $AddressBook->mobile = $requestAry["mobile"]; $result = $AddressBook->save(); if ($result) { $response->setStatusCode(202, "Accepted"); } else { $response->setStatusCode(500, "Internal Error"); } } else { $response->setStatusCode(500, "Internal Error"); } return $response; }); 34
  • 35. Phalcon Code - Delete contact $app->delete('/addressbook/{addressbookId}', function ($addressbookId) use ($app) { $response = new Response(); $AddressBook = Addressbook::findFirst($addressbookId); if ($AddressBook) { $result = $AddressBook->delete(); if ($result) { $response->setStatusCode(202, "Accepted"); } else { $response->setStatusCode(500, "Internal Error"); } } else { $response->setStatusCode(500, "Internal Error"); } return $response; }); 35
  • 36. Mission • 20%: Select a contact • 20%: Select multi contact • 20%: Create a contact • 20%: Modify a contact • 20%: Delete a contact 36
  • 37. Mission - Select multi contact 37
  • 38. Mission - Select a contact 38
  • 39. Mission - Create a contact 39
  • 40. Mission – Modify a contact 40
  • 41. Mission – Delete a contact 41