このページの2つのバージョン間の差分を表示します。
次のリビジョン | 前のリビジョン | ||
apricot:usage:ja:utility [2020/07/29 13:34] tanaka 作成 |
apricot:usage:ja:utility [2020/09/03 13:47] (現在) y2sunlight [Apricot ユーティリティ] |
||
---|---|---|---|
行 1: | 行 1: | ||
- | > 編集中 | ||
- | |||
- | ---- | ||
- | |||
====== Apricot ユーティリティ ====== | ====== Apricot ユーティリティ ====== | ||
--- // | --- // | ||
- | [[apricot: | + | [[apricot: |
目次 | 目次 | ||
+ | * [[apricot: | ||
* [[apricot: | * [[apricot: | ||
+ | * [[apricot: | ||
* [[apricot: | * [[apricot: | ||
* [[apricot: | * [[apricot: | ||
- | * [[apricot: | + | * [[apricot: |
+ | * [[apricot: | ||
* [[apricot: | * [[apricot: | ||
* [[apricot: | * [[apricot: | ||
- | * [[apricot: | + | * [[apricot: |
+ | * [[apricot: | ||
+ | * [[apricot: | ||
* Apricot ユーティリティ | * Apricot ユーティリティ | ||
行 22: | 行 23: | ||
===== ボイラープレート ===== | ===== ボイラープレート ===== | ||
- | >TODO | + | |
+ | ボイラープレートは良く使うフレームワークのコードパターンを関数として使用できるようにしたヘルパー関数です。 | ||
+ | |||
+ | ==== 環境と設定 ==== | ||
+ | |||
+ | {{tablelayout? | ||
+ | ^関数^概要^ | ||
+ | |env($key, $default = null)|環境変数を返します。| | ||
+ | |app($dot = null, $default=null)|ドット表記キーで指定されたアプリケーション設定の値を返します。| | ||
+ | |app_has($dot = null)|アプリケーション設定キーが存在するかどうかを確認します。| | ||
+ | |config($key, | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code php> | ||
+ | $value = env(' | ||
+ | </ | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code php> | ||
+ | $value = app(' | ||
+ | </ | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code php> | ||
+ | $value = config(' | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | |||
+ | ==== 例外 ==== | ||
+ | |||
+ | {{tablelayout? | ||
+ | ^関数^概要^ | ||
+ | |abort(int $code, string $message=null)|HTTP例外(400, | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code php> | ||
+ | abort(400); | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | |||
+ | ==== ディレクトリー ==== | ||
+ | |||
+ | {{tablelayout? | ||
+ | ^関数^概要^ | ||
+ | |project_dir($path = null): | ||
+ | |config_dir($path = null): | ||
+ | |assets_dir($path = null): | ||
+ | |var_dir($path = null): | ||
+ | |public_dir($path = null): | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code php> | ||
+ | $dir = project_dir(); | ||
+ | $dir = project_dir(' | ||
+ | </ | ||
+ | |||
+ | 他の関数も同様に、Apricotの特定のディレクトリーを、またはその子ディレクトリーの完全パス名を返します。各ディレクトリーに関しては | ||
+ | 「[[apricot: | ||
+ | |||
+ | \\ | ||
+ | |||
+ | ==== URLとパス ==== | ||
+ | |||
+ | {{tablelayout? | ||
+ | ^関数^概要^ | ||
+ | |url($path = null): | ||
+ | |url_ver(string $filename)|アプリケーションのバージョンを含むファイルURLを返します。| | ||
+ | |route($path = null): | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code php> | ||
+ | $url = url(); | ||
+ | $url = url(' | ||
+ | $url = url(' | ||
+ | </ | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code php> | ||
+ | $url = url(' | ||
+ | </ | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code php> | ||
+ | $path = route(); // ルートパス({your-app-path})を返します。 | ||
+ | $path = route(' | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | |||
+ | ==== アクション ==== | ||
+ | |||
+ | {{tablelayout? | ||
+ | ^関数^概要^ | ||
+ | |controllerName(): | ||
+ | |actionName(): | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code php> | ||
+ | $controller = controllerName(); | ||
+ | $action = actionName(); | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | |||
+ | ==== トランスレーション ==== | ||
+ | |||
+ | {{tablelayout? | ||
+ | ^関数^概要^ | ||
+ | |< | ||
+ | |inputLabels (string $message_key): | ||
+ | |||
+ | ''< | ||
+ | |||
+ | <code php> | ||
+ | $message = __(' | ||
+ | |||
+ | // パラメータ付きメッセージの取得 | ||
+ | $message = __(' | ||
+ | </ | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code php> | ||
+ | $labels = inputLabels(' | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | |||
+ | ==== リクエスト ==== | ||
+ | |||
+ | {{tablelayout? | ||
+ | ^関数^機能^ | ||
+ | |input (string $key, $default=null)|フォームデータを取得。'' | ||
+ | |queryString (string $key, $default=null)|クエリ文字列を取得取得。'' | ||
+ | |session (string $key, $default=null)|セッション変数を取得取得。'' | ||
+ | |flash (string $key, $default=null)|フラッシュ変数を取得取得。'' | ||
+ | |cookie (string $key, $default=null)|クッキー変数を取得取得。'' | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code php> | ||
+ | $account = input(' | ||
+ | </ | ||
+ | |||
+ | 他の関数も同様に、第1引数には変数のキーを、第2引数はオプションでデフォルト値を指定することができます。リクエスト変数に関しては 「[[apricot: | ||
+ | |||
+ | \\ | ||
+ | |||
+ | ==== 前回値 ==== | ||
+ | |||
+ | {{tablelayout? | ||
+ | ^関数^概要^ | ||
+ | |old(string $key, $default = null): | ||
+ | |back(): | ||
+ | |errors(): | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code php> | ||
+ | <input type=" | ||
+ | </ | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code php> | ||
+ | return redirect(back()); | ||
+ | </ | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code php> | ||
+ | @if($errors-> | ||
+ | @foreach($errors as $key=> | ||
+ | <div class=" | ||
+ | @endforeach | ||
+ | @endif | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | |||
+ | ==== レスポンス ==== | ||
+ | |||
+ | {{tablelayout? | ||
+ | ^関数^概要^ | ||
+ | |render(string $view=null, array $variables=[])\\ : | ||
+ | |redirect(string $url)\\ : | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code php> | ||
+ | return render(" | ||
+ | </ | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code php> | ||
+ | return redirect(route(" | ||
+ | </ | ||
+ | |||
+ | これらの関数の詳細は「[[apricot: | ||
\\ | \\ | ||