0

まず、この特定のトピックについて、CakePHPの本をできるだけ読み込もうとしたのですが、どういうわけか、これを理解することはできません。

私はいくつかのモデルを持っています:

  • 一人一人が多くの仕事をすることができます
  • 各ジョブには1つのブランチがあり、各ブランチは1つの都市に属しています。

最初は再帰に依存していましたが、(明らかに)十分にカスタマイズできないため、必要なデータを取得できません。

https://github.com/jwg2s/temp

出力配列にデータが多すぎるか、ほとんどデータがないかのどちらかです。これを封じ込めることができないので、私がやろうとしていることの例を見ることができれば、それは素晴らしいことです。 。

ありがとう

4

1 に答える 1

1

クックブックを上下に読んだので、基本的な詳細をすべて説明するのではなく、包含可能なものの使用方法を説明しようとします。

モデルの-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));
}

これが、封じ込め可能なものをもう少し理解するのに役立つことを願っています。

于 2011-07-13T07:42:28.693 に答える