クックブックを上下に読んだので、基本的な詳細をすべて説明するのではなく、包含可能なものの使用方法を説明しようとします。
モデルの-functionsでcontainableを使用できfind
ます。コントローラから、またはモデルから直接。
ほとんどの場合、私はコントローラーを使用するので、そこからどのようにそれを行うかの例を示します。私もあなたの特定の例を使おうとしているので、あなたは何かを扱う必要があります。
/app/controllers/people_controller.php
function index() {
//I like to write a separate array for fields and contain
$fields = array(
'name',
'birthday',
'gender'
);
/* It's important to know, that the fields will not get included into the
* contain-array unless it's an associated model! */
$contain = array(
'Job' => array(
//within another array you define the next level of contain
'Branch' => array(
//you get the deal...
'City'
),
//if you only need specific fields you can define this here like this:
'fields' => array('title', 'date', 'salary'),
//or order them directly!
'order' => 'Job.salary DESC'
)
);
//we now to our find-fall with our 2 arrays for the fields and the contain
//every option (like fields or order) can be used in the containable
$people = $this->Person->find('all', array('contain' => $contain, 'fields' => $fields));
}
これが、封じ込め可能なものをもう少し理解するのに役立つことを願っています。