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:by -by class -f :構建表單 - a :build api -e :在此之後啟用日誌記錄,它將列出所有表格,並且可以通過“ a”或“ a”或“ comma”或“ comma for your”(1,4,4,4,5 ...)選擇所有表格,然後選擇所有表格。所有類,表格和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/user/? findbynamelike = john&limit = 10#將以json格式輸出所有用戶信息,將標準和限制匹配到10
http:// localhost:8080/api/user/123#將輸出用戶123 json格式的信息
是的,那是真的!但是,您可以將其配置為僅通過編輯文件來公開所需的列(默認情況下)
/api/src/RouteAPI.php
這是由公用事業生成的。對於每個表,在該文件中創建和硬編碼的列數組,如果該數組中存在列名,則數據將公開,否則未顯示,並且BTW,安全性不是Lazymephp的責任。
啟用此選項後,將3個表添加到您的數據庫中,這些表將註冊到數據庫的所有更改。唯一需要完成的配置是編輯
/src/Configuration/Configurations.php
並定義用戶驗證要註冊為數據庫中更改的所有者
// ACTIVITY LOG
$CONFIG['APP_ACTIVITY_LOG']=1;
$CONFIG['APP_ACTIVITY_AUTH']=$_SESSION['user_logged'];
查看器不在 /記錄中,並顯示按日期desc訂購的請求列表,並且可以使用一些過濾器。這不是一個全面的觀眾,您可以將其視為擴展的一個例子(但確實運行良好)
麻省理工學院