Behavior 16 Model 層の比較 The CakePHP ORM borrows ideas and concepts from both ActiveRecord and Datamapper patterns. It aims to create a hybrid implementation that combines aspects of both patterns to create a fast, simple to use ORM. CakePHP の ORM はアクティブレコードやデータマッパーパターンのアイ デアやコンセプトを拝借しています。 その目的は、早く作成し、シンプ ルに ORM を利用するという2つの利点を混成させるためです。
to save new records, modify/delete existing ones, define relations, and perform bulk operations. これらを利用することで、新しいレコードを保存したり、 既存データの 編集/削除、リレーションの定義、そして一括処理ができます。 Entities represent individual records and allow you to define row/record level behavior & functionality. エンティティーは、個々のレコードを意味し、 行/レコードレベルの振る 舞いや機能の定義を可能にします。
• 共通処理は Behavior • テーブル単位の操作の Table • レコード単位の操作は Entity 18 Model 層の比較 Behaviors provide a convenient way to package up behavior that is common across many models. ビヘイビアーは、多くのモデルで共通の振る舞いをまとめる便利な方法を 提供します。
層の比較 When getting started with Laravel, many developers are confused by the lack of a models directory. However, the lack of such a directory is intentional. We find the word "models" ambiguous since it means many different things to many different people. For this reason, we choose to place Eloquent models in the app directory by default, and allow the developer to place them somewhere else if they choose.
make:model の説明 「Create a new Eloquent model class」 • 【考察】 • ORM 即ち Model という意味ではない • Eloquent model class にビジネスロジックを 記述してもよい • Eloquent model class を単なる ORM とみなし 他の階層構造にビジネスロジックを記述してもよい 20 Model 層の比較
• 【私見】では「エロクワント」と読む 21 Model 層の比較 The Eloquent ORM included with Laravel provides a beautiful, simple ActiveRecord implementation for working with your database.
58 View 層の比較 Views contain the HTML served by your application and separate your controller / application logic from your presentation logic. . : ├── resources : : │ └── views :
59 View 層の比較 Blade is the simple, yet powerful templating engine provided with Laravel. Unlike other popular PHP templating engines, Blade does not restrict you from using plain PHP code in your views. 条件分岐 繰り返し @if ($isSucceeded) {{ $message }} @endif @foreach ($items as $item) {{ $item['name'] }} @endforeach
: │ ├── Controller/ │ │ └── Component/ : : Your controller should handle interpreting the request data, making sure the correct models are called, and the right response or view is rendered. Controllers can be thought of as middle layer between the Model and View. コントローラーはリクエストを解釈して、適切なモデルが 呼ばれるのを 確認して、正しいレスポンスまたはビューを書き出します。コントロー ラーはモデルとビューの 中間層とみなすことができます。
Controller 層の比較 Instead of defining all of your request handling logic as Closures in route files, you may wish to organize this behavior using Controller classes. . ├── app : : │ ├── Http/ │ │ ├── Controllers/ │ │ : : :
Controller 層の比較 In addition to constructor injection, you may also type-hint dependencies on your controller's methods. class UserController extends Controller { /** * Store a new user. * * @param Request $request * @return Response */ public function store(Request $request) { $name = $request->name; // } }
→テストの書きやすいコードに 76 その他特徴 The Laravel service container is a powerful tool for managing class dependencies and performing dependency injection. class UserController extends Controller { protected $users; public function __construct(UserRepository $users) { $this->users = $users; }
デフォルトで Log, DB, Session などといった Facade を提供 • 自分で Facade 実装することもできる 77 その他特徴 Facades provide a "static" interface to classes that are available in the application's service container. Laravel ships with many facades which provide access to almost all of Laravel's features. ¥DB::transaction(function () { // トランザクション開始 }); ¥Log::debug('debug log'); ¥Log::info('info log'); ¥Log::error('error log');