Lazymephp เป็นกรอบการเรียนรู้/ใช้ PHP ขนาดเล็กและง่ายที่ฉันใช้มานานแล้วด้วยความสำเร็จและมีคุณสมบัติที่ดี:
ความคิดที่อยู่เบื้องหลัง Lazymephp คือการอนุญาตให้ฉันขี้เกียจดังนั้นเพื่อช่วยในงานนั้นมันต้องมีการตั้งฐานฐานข้อมูลที่เหมาะสมด้วยตารางและความสัมพันธ์ระหว่างพวกเขา
ข้อ จำกัด เพียงอย่างเดียวคือคุณ ต้อง มีคีย์หลักในแต่ละตาราง
หากโครงสร้างของฐานข้อมูลจำเป็นต้องมีการเปลี่ยนแปลง (คอลัมน์เพิ่ม/ลบ/ลบสิ่งใดก็ตาม) คุณสามารถสร้างรหัสทั้งหมดใหม่ได้ตลอดเวลา (ด้วยข้อควรระวังบางอย่าง)
git clone https://github.com/Peixinho/LazyMePHP myAwesomeProject
#optional, but I advise to start your own git repository, for many reasons...
cd myAwesomeProject && rm -rf .git
cd src/Ext
composer update (to get dependencies)
# run initial config
php LazyMePHP config
ตอนนี้จะเรียกใช้ตัวกำหนดค่าเริ่มต้นในบรรทัดคำสั่งซึ่งคุณต้องเติมรายการต่อไปนี้:
ถัดไปคุณสามารถเรียกใช้
php LazyMePHP build
หากคุณใช้เครื่องมือนี้หลังจากการสร้างครั้งแรกและคุณได้ทำการเปลี่ยนแปลงรูปแบบที่สร้างขึ้น API หรือคลาส (คุณไม่ควรเปลี่ยนคลาสที่สร้างขึ้นของคุณต่อไป) การเปลี่ยนแปลงของคุณอาจหายไปเครื่องมือนี้ใช้ตารางดังนั้นหากคุณเปลี่ยนรูปแบบตารางเฉพาะหรือ API อย่าเลือก
หลังจากนี้คุณจะมีรายการตารางฐานข้อมูลของคุณซึ่งคุณสามารถเลือกสิ่งที่จะสร้างและตัวเลือกอื่น ๆ : - D : การเปลี่ยนแปลงตัวบ่งชี้ตาราง - C : สร้างคลาส - F : สร้างแบบฟอร์ม - A : สร้าง API - E : เปิดใช้งานการบันทึกหลังจากนี้จะแสดงรายการทั้งหมดและคุณสามารถเลือกได้ทั้งหมด นี่เป็นสิ่งเดียวกันสำหรับทุกคลาสแบบฟอร์มและ API
หากทุกอย่างเป็นไปด้วยดีคุณจะมีดัชนีการทำงานที่มีฟังก์ชั่นพื้นฐานบางอย่าง
php LazyMePHP serve
และนำทางไปยัง
http://localhost:8080
| ผู้ใช้ |
|---|
| PK ID |
| FK CountryID |
| ชื่อ |
| อายุ |
| ประเทศ |
|---|
| PK CountryID |
| ชื่อประเทศ |
มี pk country.countryid -> fk user.countryid
ทุกตารางที่สร้างขึ้นจะมีแบบฟอร์มที่ใช้งานได้ดังนี้:
## Classes
Every table generated will have a class that works as follows:
- Each Table will have a Class File by default in /src/Classes/[Table Name].php
- All Classes will be in namespace LazyMePHPClasses
- All Class columns have getters and setters *Get*[Column Name], *Set*[Column Name]
- All Classes have Save method, if Id is provided when constructing object:
```
$user = new User(); $user->Save(); // Will act as an INSERT
...
$user = new User(123); $user->Save(); // Will act as an UPDATE
```
-All classes have a Delete method, if id was provided upon constructing object
- Foreign members can be built automatically
```
// Country
$pt = new LazyMePHPClassesCountry();
$pt->SetCountryName('Portugal');
$pt->Save();
// User
$user = new LazyMePHPClassesUser();
$user->SetName('Peter');
$user->SetAge('30');
$user->SetCountryId($pt->Getid());
$user->Save();
echo $user->GetId(); // e.g. 123 - id is the primary key in User Table
// Retrieving user data and changing it
$user = new LazyMePHPClassesUser(123);
echo $user->GetName(); // 'Peter'
$user->Setname('John');
$user->Save();
// Access Foreign members by uing Get[Column Name]Object
echo $user->GetCountryIdObject()->GetCountryName();
// And changing it
$user->GetCountryIdObject()->SetCountry('England'); // Of course, you are changing Country Name in Country Table
$user->GetCountryIdObject()->Save();
# Not building Foreign members
$user = new LazyMePHPClassesUser(5, false); // this won't query foreign tables
```
- Every class will have a *table*_list class, that allows you to select a list of that class type
- Every List have a *FindBy*[Foreign Column Name], *FindBy*[Foreign Column Name]*Like*, *OrderBy*[Foreign Column name], *GroupBy*[Foreign Column], *Limit*
```
$users = new LazyMePHPClassesUser_List();
$users->FindByNameLike('John');
$users->OrderByAge();
// As in regular classes, you can or not build foreign tables, by default is building them
foreach($users->GetList() as $u) { echo $u->GetName(); echo $u->GetCountryIdObject()->GetCountryName(); }
// Not building foreign members
foreach($users->GetList(false) as $u) ...
```
## API
Every table generated will have some routes created in src/api/RouteAPI.php, and they make use of the controllers of each table
- Accessible from /api/[Table Name]/ (.htaccess for apache, didnt bother with others)
http: // localhost: 8080/api/user/ # จะส่งออกข้อมูลผู้ใช้ทั้งหมดในรูปแบบ JSON
http: // localhost: 8080/api/ผู้ใช้/? findBynamelike = john & limit = 10 # จะส่งออกข้อมูลผู้ใช้ทั้งหมดในรูปแบบ JSON ที่ตรงกับเกณฑ์และขีด จำกัด ถึง 10
http: // localhost: 8080/api/user/123 # จะส่งออกผู้ใช้ 123 ข้อมูลในรูปแบบ JSON
ใช่จริง! อย่างไรก็ตามคุณสามารถกำหนดค่าให้แสดงเฉพาะคอลัมน์ที่คุณต้องการ (ทั้งหมดตามค่าเริ่มต้น) โดยการแก้ไขไฟล์
/api/src/RouteAPI.php
ที่สร้างขึ้นโดยสาธารณูปโภค สำหรับแต่ละตารางอาร์เรย์ของคอลัมน์จะถูกสร้างและ hardcoded ในไฟล์นั้นและหากชื่อคอลัมน์มีอยู่ภายในอาร์เรย์นั้นข้อมูลจะถูกเปิดเผยมิฉะนั้นจะไม่แสดงและ BTW ความปลอดภัยไม่ได้เป็นความรับผิดชอบของ Lazymephp
เมื่อเปิดใช้งานตัวเลือกนี้จะมีการเพิ่ม 3 ตารางลงในฐานข้อมูลของคุณที่จะลงทะเบียนทุกการเปลี่ยนแปลงที่เกิดขึ้นกับฐานข้อมูล การกำหนดค่าเพียงอย่างเดียวที่จำเป็นต้องทำคือแก้ไข
/src/Configuration/Configurations.php
และกำหนดว่าการรับรองความถูกต้องของผู้ใช้จะลงทะเบียนเป็นเจ้าของการเปลี่ยนแปลงในฐานข้อมูลคืออะไร
// ACTIVITY LOG
$CONFIG['APP_ACTIVITY_LOG']=1;
$CONFIG['APP_ACTIVITY_AUTH']=$_SESSION['user_logged'];
ผู้ชมอยู่ภายใต้ /การบันทึกและแสดงรายการคำขอที่สั่งโดย Date DESC และมีตัวกรองบางตัวที่สามารถใช้งานได้ นี่ไม่ใช่ผู้ชมที่โดดเด่นเต็มรูปแบบคุณสามารถเห็นได้ว่าเป็นตัวอย่างในการขยาย (แต่มันใช้งานได้ค่อนข้างดี)
มิกซ์