Lazymephpは、私がかなり長い間使用してきたPHPフレームワークを小さくて簡単に使用できる/使用しやすいものであり、成功しています。
Lazyephpの背後にあるアイデアは、私が怠zyになることを可能にすることです。そのため、そのタスクを支援するためには、そのテーブルとそれらの間の関係を備えた適切なデータベースを設定する必要があります。
唯一の制限は、各テーブルに主要なキーを実際に持っている必要があることです。
データベースの構造を変更する必要がある場合(列を追加/削除します)、すべてのコードを常に再生することができます(いくつかの予防措置を備えています)。
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、またはクラスに変更を加えた場合(とにかく生成されたクラスを変更する必要はありません)、変更は失われる可能性があります。このツールはテーブルベースです。
この後、データベーステーブルのリストを作成します。ここでは、何を構築するか、その他のオプションを選択できます。 -d :Change Table descriptors -c :build classes -f :build forms -a :build api -e :enable logging logging enable logging this all fort for for 'a'、またはcommaを選択します(1,4,5,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#すべてのユーザー情報が基準に一致して10に一致するJSON形式で出力します
http:// localhost:8080/api/user/123#は、json形式のユーザー123情報を出力します
ええ、それは本当です!ただし、ファイルを編集することにより、必要な列のみ(デフォルトで)のみを公開するように構成できます
/api/src/RouteAPI.php
それはユーティリティによって生成されます。各テーブルについて、そのファイルに一連の列が作成され、ハードコードされ、列名がその配列内に存在する場合、データが公開されます。
このオプションを有効にすると、データベースに行われたすべての変更を登録する3つのテーブルがデータベースに追加されます。行う必要がある唯一の構成は編集することです
/src/Configuration/Configurations.php
データベースの変更の所有者として登録されるユーザー認証を定義します
// ACTIVITY LOG
$CONFIG['APP_ACTIVITY_LOG']=1;
$CONFIG['APP_ACTIVITY_AUTH']=$_SESSION['user_logged'];
Viewerは下 /ロギングをしており、Date DESCで注文されたリクエストのリストを表示し、使用できるフィルターがいくつかあります。これは完全な視聴者ではありません。拡張する例として見ることができます(ただし、非常にうまく機能します)
mit