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订购的请求列表,并且可以使用一些过滤器。这不是一个全面的观众,您可以将其视为扩展的一个例子(但确实运行良好)
麻省理工学院