SlideShare a Scribd company logo
行動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

More Related Content

PDF
Getting out of Callback Hell in PHP
PPTX
Алексей Плеханов: Новинки Laravel 5
PDF
Getting Started-with-Laravel
PDF
Using HttpKernelInterface for Painless Integration
PPTX
23.simple login with sessions in laravel 5
PDF
エラー時にログに出力する情報と画面に表示する情報を分ける #LaravelTokyo
PPTX
Laravel Beginners Tutorial 2
PPTX
21.search in laravel
Getting out of Callback Hell in PHP
Алексей Плеханов: Новинки Laravel 5
Getting Started-with-Laravel
Using HttpKernelInterface for Painless Integration
23.simple login with sessions in laravel 5
エラー時にログに出力する情報と画面に表示する情報を分ける #LaravelTokyo
Laravel Beginners Tutorial 2
21.search in laravel

What's hot (7)

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

Similar to 20160105 wnmp & phalcon micro app - part II (11)

PPTX
20151229 wnmp & phalcon micro app - part I
PDF
Quick run in with Swagger
ODP
PHPUnit elevato alla Symfony2
PPTX
Cakefest 2010: API Development
PPTX
Day02 a pi.
PDF
Phalcon / Zephir Introduction at PHPConfTW2013
PDF
Startup eng-camp 3
PDF
api-platform: the ultimate API platform
PDF
Android App Development 06 : Network &amp; Web Services
PPT
Stop Making The Web Harder Than It Is; Real-world REST, HATEOAS, and Hypermed...
PDF
Applications for the Enterprise with PHP (CPEurope)
20151229 wnmp & phalcon micro app - part I
Quick run in with Swagger
PHPUnit elevato alla Symfony2
Cakefest 2010: API Development
Day02 a pi.
Phalcon / Zephir Introduction at PHPConfTW2013
Startup eng-camp 3
api-platform: the ultimate API platform
Android App Development 06 : Network &amp; Web Services
Stop Making The Web Harder Than It Is; Real-world REST, HATEOAS, and Hypermed...
Applications for the Enterprise with PHP (CPEurope)
Ad

More from Taien Wang (19)

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

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Machine Learning_overview_presentation.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
A Presentation on Artificial Intelligence
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Empathic Computing: Creating Shared Understanding
PDF
Electronic commerce courselecture one. Pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Machine Learning_overview_presentation.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
A Presentation on Artificial Intelligence
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Encapsulation_ Review paper, used for researhc scholars
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
The AUB Centre for AI in Media Proposal.docx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
A comparative analysis of optical character recognition models for extracting...
MYSQL Presentation for SQL database connectivity
Building Integrated photovoltaic BIPV_UPV.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Mobile App Security Testing_ A Comprehensive Guide.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Empathic Computing: Creating Shared Understanding
Electronic commerce courselecture one. Pdf

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