เดี่ยวนี้ framework ต่างๆก็ใช้ package manager อย่าง composer ติดตั้ง library ต่างๆ รวมทั้งติดตั้ง framework อื่นๆ อย่าง jQuery ถ้าต้องการที่จะสร้างโครงการของเราเองก็ทำได้ง่ายๆ
- สร้าง folder ใหม่ขึ้นมา เช่น C:\xampp\htdocs\snippets
- พิมพ์[code language=”text” title=”command”]composer init[/code]
- ตอบคำถามไปตามละดับ เช่น [code language=”text” title=”command”]
D:\>cd D:\xampp\htdocs\snippetsD:\xampp\htdocs\snippets>composer init
Welcome to the Composer config generator
This command will guide you through creating your composer.json config.
Package name (<vendor>/<name>) [pitt.p/snippets]: pitt/snippets
Description []: code snippets
Author [, n to skip]: Pitt Phunsanit <[email protected]>
Minimum Stability []: stable
Package Type (e.g. library, project, metapackage, composer-plugin) []: project
License []: mitDefine your dependencies.
Would you like to define your dependencies (require) interactively [yes]? yes
Search for a package: jqueryFound 15 packages matching jquery
[0] components/jquery
[1] frameworks/jquery
[2] contao-components/jquery
[3] yiisoft/jquery
[4] etdsolutions/jquery
[5] ovidentia/jquery
[6] mygento/jquery
[7] quickapps-plugins/jquery
[8] intelogie/jquery
[9] apnet/jquery
[10] jquery/jquery
[11] yepsua/jquery4php
[12] venne/jquery2.0-module
[13] sonata-project/jquery-bundle
[14] blueimp/jquery-file-uploadEnter package # to add, or the complete package name if it is not listed: 0
Enter the version constraint to require (or leave blank to use the latest version):
[/code] - ตอบคำถามไปเรื่อยๆ รูปแบบ packages จะสัมพันกับ url ใน github เช่น https://github.com/jquery/jquery ถ้าไม่ทราบหาได้ขากเว้บ packagist.org จนสุดท้ายจะสร้างไฟล์ composer.json ขึ้นมา[code language=”javascript” title=”composer.json”]
{
"authors": [{
"email": "[email protected]",
"homepage": "https://pitt.plusmagi.com",
"name": "pitt phunsanit",
"role": "Developer"
}],
"description": "snippet",
"homepage": "https://pitt.plusmagi.com",
"license": "mit",
"minimum-stability": "stable",
"name": "pitt/snippet",
"require": {
"ckeditor/ckeditor": "*",
"components/jquery": "*",
"components/jquery-migrate": "*",
"components/jqueryui": "*",
"phpoffice/phpexcel": "^1.8",
"twbs/bootstrap": "*"
},
"type": "project"
}[/code] - โหลด library โดยคำสั่ง[code language=”text” title=”command”]composer update[/code]
ไฟล์จุถูกเก็บในโฟลเดอร์ vendor/xxx/yyy อย่างเรียบร้อยและเหมือนกันทุกเครื่องถ้าลง package เดียวกัน version เดียวกัน
About the author