Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion ja/appendices/3-4-migration-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ PSR-7 スタックによって廃止されているため、 非推奨になり
* ``Event::result()`` は非推奨です。代わりに ``Event::getResult()`` を使用してください。
* ``Event::data()`` は非推奨です。代わりに ``Event::getData()`` を使用してください。
* ``Auth.redirect`` セッション変数は使用されなくなりました。
代わりに、リダイレクト URL を格納するためにクエリ文字列パラメータが使用されます。
代わりに、リダイレクト URL を格納するためにクエリ文字列パラメーターが使用されます。
これには、ログインシナリオ外のセッションにリダイレクト URL を格納する機能を削除するという
追加の効果があります。
* ``AuthComponent`` は、許可されていないURLが ``GET`` アクション以外の場合、
リダイレクト URL を保存しません。
* ``AuthComponent`` の ``ajaxLogin`` オプションは非推奨です。
Expand Down Expand Up @@ -332,6 +334,13 @@ CakePHP の以前のバージョンでは、コンポーネントは後で変更
* ``Mailer\Email`` は、コンテンツタイプが提供されていない場合、 ``mime_content_type`` を使って
添付ファイルタイプを自動検出します。これまでの添付ファイルはデフォルトで
'application/octet-stream' になっていました。
* CakePHP は、現在、 ``call_user_func_array()`` の代わりに ``...`` 演算子を使用します。
連想配列を渡す場合は、次のメソッドには ``array_values()`` を使って数値添字配列を渡すように
コードを更新する必要があります。

* ``Cake\Mailer\Mailer::send()``
* ``Cake\Controller\Controller::setAction()``
* ``Cake\Http\ServerRequest::is()``

アクセス権の変更
================
Expand Down
15 changes: 8 additions & 7 deletions ja/controllers/components/authentication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,16 @@ all キーは ``AuthComponent::ALL`` と記述することもできます。 ::
.. php:method:: redirectUrl

ユーザーがログインした後、一般的に彼らが来たところに戻すのにリダイレクトすることになるでしょう。
ユーザーがログイン時にリダイレクトされるべき目的地を設定するために、URL を渡してください。
ユーザーがログインした後にリダイレクトされるべき目的地を設定するために、URL を渡してください。

パラメータが渡されない場合は、認証のリダイレクト URL を取得します。
返される URL は、以下の規則に従います。
パラメーターが渡されない場合、返される URL は、次の規則に従います。

- セッションの Auth.redirect 値が存在していて、同じドメインの現在のアプリが実行されている場合は、
その値から正規化された URL を返します。
- セッション値がなく ``loginRedirect`` の設定がある場合は、 ``loginRedirect`` の値を返します。
- セッションがなく ``loginRedirect`` がない場合は、/ を返します。
- ``redirect`` クエリー文字列が存在していて、同じドメインの現在のアプリが実行されている場合は、
正規化された URL を返します。 3.4.0 より前は、セッションの ``Auth.redirect`` の値が
使用されていました。
- クエリー文字列やセッション値がなく ``loginRedirect`` の設定がある場合は、
``loginRedirect`` の値を返します。
- セッションがなく ``loginRedirect`` がない場合は、 ``/`` を返します。


ステートレス認証システムの作成
Expand Down
12 changes: 12 additions & 0 deletions ja/controllers/request-response.rst
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,12 @@ Accept ヘッダの確認
return $response;
}

// 3.4.0 より前
$file = $this->Attachments->getFile($id);
$this->response->file($file['path']);
// レスポンスオブジェクトを返すとコントローラがビューの描画を中止します
return $this->response;

上記の例のようにメソッドにファイルのパスを渡す必要があります。CakePHP は、
`Cake\\Http\\Reponse::$_mimeTypes` に登録された、よく知られるファイルタイプであれば
正しいコンテンツタイプヘッダを送ります。 :php:meth:`Cake\\Http\\Response::withFile()` を呼ぶ前に
Expand All @@ -481,6 +487,12 @@ Accept ヘッダの確認
['download' => true, 'name' => 'foo']
);

// 3.4.0 より前
$this->response->file(
$file['path'],
['download' => true, 'name' => 'foo']
);

サポートされているオプションは次のとおりです。

name
Expand Down
2 changes: 1 addition & 1 deletion ja/core-libraries/collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ PHP 5.5 以降を使用している場合は、 コレクション内の各ア

コレクションのソート順を指定するには、昇順や降順にソートするために、2番目のパラメータに
``SORT_ASC`` や ``SORT_DESC`` のどちらかを指定する必要があります。
デフォルトでは、コレクションは昇順にソートされます。 ::
デフォルトでは、コレクションは降順にソートされます。 ::

$collection = new Collection($people);
$sorted = $collection->sortBy('age', SORT_ASC);
Expand Down
12 changes: 12 additions & 0 deletions ja/core-libraries/internationalization-and-localization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,18 @@ ORM で返されるデフォルトの日付では結果は ``Cake\I18n\Time``
``LocaleSelectorFilter`` をアプリケーション内で使用すると、CakePHP は自動で現在のユーザに基づいた
ロケールを設定します。 ::

// src/Application.php の中で
use Cake\I18n\Middleware\LocaleSelectorMiddleware;

// 新しいミドルウェアを追加するために middleware 関数を更新してください。
public function middleware($middleware)
{
// ミドルウェアの追加し、有効なロケールの設定
$middleware->add(new LocaleSelectorMiddleware(['en_US', 'fr_FR']));
}


// 3.3.0 より前は、 DispatchFilter を使用してください。
// config/bootstrap.php 内で
DispatcherFactory::add('LocaleSelector');

Expand Down
8 changes: 4 additions & 4 deletions ja/core-libraries/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ CakePHP のバリデーションは、任意の配列データに対するバリ
このことが、このクラスにおけるメソッドをバリデーションルールとして使用することを容易にします。
バリデータと ORM をともに用いる場合は、テーブル及びエンティティのオブジェクトのために
追加のプロバーダーが設定されます。アプリケーションの用途に応じてプロバイダーを追加したい場合は、
``provider()`` メソッドを用います。 ::
``setProvider()`` メソッドを用います。 ::

$validator = new Validator();

// オブジェクトインスタンスを用いる。
$validator->provider('custom', $myObject);
$validator->setProvider('custom', $myObject);

// クラス名を用いる。メソッドは静的なものでなければならない。
$validator->provider('custom', 'App\Model\Validation');
$validator->setProvider('custom', 'App\Model\Validation');

バリデーションプロバイダーは、オブジェクトか、あるいはクラス名で設定されます。
クラス名が使用されるのであれば、メソッドは静的でなければなりません。
Expand All @@ -200,7 +200,7 @@ CakePHP のバリデーションは、任意の配列データに対するバリ
public function validationDefault(Validator $validator)
{
// バリデータにプロバイダーを追加
$validator->provider('fr', 'Localized\Validation\FrValidation');
$validator->setProvider('fr', 'Localized\Validation\FrValidation');
// フィールドのバリデーションルールの中にプロバイダーを利用
$validator->add('phoneField', 'myCustomRuleNameForPhone', [
'rule' => 'phone',
Expand Down
4 changes: 2 additions & 2 deletions ja/development/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,8 @@ POST リクエストの中の、 \_method の値を使う方法は、ブラウ
Router::scope('/', function ($routes) {
$routes->resources('BlogPosts', [
'inflect' => 'dasherize' // ``Inflector::dasherize()`` を使用
];
})
]);
});

上記は、 **/blog-posts/\*** スタイルの URL を生成します。

Expand Down
90 changes: 44 additions & 46 deletions ja/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ CakePHP のインストール

php -v

少なくとも PHP |minphpversion| (CLI) 以上がインストールされていなければなりません。
PHP |minphpversion| (CLI) 以上がインストールされていなければなりません。
ウェブサーバー版の PHP もまた |minphpversion| 以上でなければりませんし、
コマンドラインインターフェース (CLI) 版の PHP と同じバージョンがベストです
コマンドラインインターフェース (CLI) 版と同じバージョンを使用してください

Composer のインストール
-----------------------
Expand All @@ -78,8 +78,8 @@ CakePHP の公式のインストール方法として、依存性管理ツール
CakePHP プロジェクトを作成
--------------------------

以上で、Composer をダウンロードとインストールしました。my_app_name フォルダに CakePHP
の新しいアプリケーションを作りたいなら、下記の composer コマンドを実行して作成します。
以上で、Composer をダウンロードとインストールしましたので、 my_app_name フォルダに
CakePHP の新しいアプリケーションを作成してください。下記の composer コマンドを実行して作成します。

.. code-block:: bash

Expand Down Expand Up @@ -107,8 +107,8 @@ composer によるインストールが推奨されますが、
また、 ``composer.phar`` も入っていますので、あなたのさらなる使用のために必要なものは
全てそろっているのです。

CakePHPの変更に合わせて最新の状態に保つ
---------------------------------------
CakePHP の変更に合わせて最新の状態に保つ
----------------------------------------

デフォルトではあなたのアプリケーションの **composer.json** は下記のようになっています。 ::

Expand All @@ -132,6 +132,21 @@ CakePHPの変更に合わせて最新の状態に保つ
さらに、composer は開発ブランチをキャッシュしませんので、composer による
連続したインストール・アップデートには時間がかかります。

Oven を使用したインストール
---------------------------

CakePHP を素早くインストールするための別の方法は、 `Oven <https://github.com/CakeDC/oven>`_ です。
これは、必要なシステム要件をチェック、CakePHP アプリケーションのスケルトンをインストール、そして、
開発環境をセットアップするシンプルな PHP スクリプトです。

インストールが完了すれば、あなたの CakePHP アプリケーションはすぐに使えます!

.. note::

重要: これはデプロイスクリプトではありません。はじめて CakePHP をインストールする開発者を助け、
開発環境を素早くセットアップすることが狙いです。本番環境では、ファイルのパーミッション、
バーチャルホストの設定など、いくつかの要因を考慮する必要があります。

パーミッション
==============

Expand Down Expand Up @@ -371,7 +386,7 @@ CakePHP は、展開した状態では mod_rewrite を使用するようにな
`virtualhostx <http://clickontyler.com/virtualhostx/>`_
ツールを使うことが挙げられます。

多くのホスティングサービス (GoDaddy、1and1) では、実際にウェブサーバーが
多くのホスティングサービス (GoDaddy、1and1) では、ウェブサーバーが
既に mod\_rewrite を使っているユーザディレクトリから配信されます。
CakePHP をユーザディレクトリ (http://example.com/~username/cakephp/) または
既に mod\_rewrite を活用しているその他の URL 構造にインストールしているなら、
Expand Down Expand Up @@ -424,21 +439,31 @@ nginx は Apache のような .htaccess ファイルを利用しませんので
これは大抵 ``/etc/nginx/sites-available/your_virtual_host_conf_file`` に記載します。
あなたの環境構成に応じて、このファイルを書き換えなければなりませんが、
少なくとも PHP を FastCGI として稼働させる必要はあるでしょう。
下記の設定は、リクエストを ``webroot/index.php`` にリダイレクトします。

.. code-block:: nginx

location / {
try_files $uri $uri/ /index.php?$args;
}

server ディレクティブの例は、次の通りです。

.. code-block:: nginx

server {
listen 80;
listen [::]:80;
server_name www.example.com;
rewrite ^(.*) http://example.com$1 permanent;
return 301 http://example.com$request_uri;
}

server {
listen 80;
listen [::]:80;
server_name example.com;

# root directive should be global
root /var/www/example.com/public/webroot/;
root /var/www/example.com/public/webroot;
index index.php;

access_log /var/www/example.com/log/access.log;
Expand All @@ -450,46 +475,19 @@ nginx は Apache のような .htaccess ファイルを利用しませんので

location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}

(Ubuntu 14.04 など) いくつかのサーバでは、上記のような設定は動かないでしょうから、 nginx の
ドキュメントでは別の方法 (http://nginx.org/en/docs/http/converting_rewrite_rules.html)を
推奨しています。
下記の通り試してみてください。(server{}ブロックが2つではなく1つになっているのが
お分かりでしょう。)

.. code-block:: nginx

server {
listen 80;
server_name www.example.com;
rewrite 301 http://www.example.com$request_uri permanent;

# root directive should be global
root /var/www/example.com/public/webroot/;
index index.php;

access_log /var/www/example.com/log/access.log;
error_log /var/www/example.com/log/error.log;

location / {
try_files $uri /index.php?$args;
}

location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}

.. note::
最近の PHP-FPM の設定では、アドレス 127.0.0.1 の TCP 9000 ポートの代わりに unix php-fpm
ソケッットを待ち受けるように設定します。もし、上記の設定で 502 bad gateway エラーになった場合、
TCP ポートの代わりに unix ソケットパスを使用するために ``fastcgi_pass`` を更新してください
(例: fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;)。

IIS7 (Windows hosts)
--------------------
Expand Down
12 changes: 6 additions & 6 deletions ja/orm/saving-data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,6 @@ Table クラスは、リクエストデータを一つまたは複数のエン
]
]);

入れ子になったアソシエーションの変換を無効にする時は、次のようになります。 ::

$entity = $articles->newEntity($data, ['associated' => []]);
// または...
$entity = $articles->patchEntity($entity, $data, ['associated' => []]);

上記は 'Tags' 、 'Comments' そして Comments 用の 'Users' が変換されるべきであること
を示しています。代わりに、簡潔にするためにドット記法を使うことができます。 ::

Expand All @@ -233,6 +227,12 @@ Table クラスは、リクエストデータを一つまたは複数のエン
'associated' => ['Tags', 'Comments.Users']
]);

入れ子になったアソシエーションの変換を無効にする時は、次のようになります。 ::

$entity = $articles->newEntity($data, ['associated' => []]);
// または...
$entity = $articles->patchEntity($entity, $data, ['associated' => []]);

関連付けられたデータもまた、指定しない限り、既定では検証されます。
アソシエーションごとに使われる検証セットを変更することもできます。 ::

Expand Down