2011-07-15 12 views
0

私は、私がメインモデルに関連付けられているモデルでgroupableを使用しようとしているシナリオを持っています。CakePHP、Containable、Group投稿者

Array 
(
    [Subfirm] => Array 
     (
      [id] => 1 
      [firm_id] => 1 
      [name] => Word Spam Management Fund 
      [description] => There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc. 
      [active] => yes 
      [created] => 2011-07-14 18:05:01 
      [modified] => 2011-07-14 18:05:01 
     ) 

    [Firm] => Array 
     (
      [id] => 1 
      [name] => Word Spam 
      [description] => Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean dictum neque a arcu ultricies semper. Curabitur lacinia, nisi ac cursus mattis, diam ipsum egestas eros, id pharetra dui quam vel sapien. Fusce tempus mauris eu ligula rutrum rutrum. Cras sit amet metus nisl. Nam feugiat malesuada justo, lacinia mollis nulla iaculis sed. Sed dui sapien, aliquam vel vestibulum eget, suscipit ac dui. Donec et neque dapibus lorem euismod convallis. Sed nec mauris vel velit venenatis fermentum et non velit. Pellentesque tincidunt, nisi vitae sollicitudin malesuada, lectus orci egestas neque, vitae placerat magna nisi eu nulla. Donec eleifend laoreet ligula vitae faucibus. Donec eget felis eros. Nullam ligula nisl, porttitor at viverra a, auctor ullamcorper orci. Fusce vestibulum turpis mollis velit tristique luctus. 
      [website] => http://www.wordspam.com 
      [active] => yes 
      [created] => 2011-07-11 11:33:46 
      [firmtype_id] => 1 
      [aum] => 600.77 
      [modified] => 2011-07-10 22:55:16 
      [Firmtype] => Array 
       (
        [id] => 1 
        [name] => Hedge Fund 
        [active] => yes 
        [created] => 2011-07-12 12:30:42 
        [modified] => 2011-07-12 12:30:42 
       ) 

     ) 

    [Subfirmdetail] => Array 
     (
      [0] => Array 
       (
        [id] => 1 
        [subfirm_id] => 1 
        [subfirmdetailtype_id] => 1 
        [value] => 400 
        [date] => 2011-07-14 
        [created] => 2011-07-14 19:09:42 
        [modified] => 2011-07-14 19:09:42 
        [active] => yes 
        [Subfirmdetailtype] => Array 
         (
          [id] => 1 
          [firmtype_id] => 1 
          [name] => AUM 
          [datatype_id] => 1 
          [created] => 2011-07-14 18:09:23 
          [modified] => 2011-07-14 18:09:23 
          [active] => yes 
          [Datatype] => Array 
           (
            [id] => 1 
            [name] => DOUBLE 
            [created] => 2011-07-14 18:14:58 
            [modified] => 2011-07-14 18:14:58 
            [active] => yes 
           ) 

         ) 

       ) 

      [1] => Array 
       (
        [id] => 2 
        [subfirm_id] => 1 
        [subfirmdetailtype_id] => 2 
        [value] => 2.34 
        [date] => 2011-07-14 
        [created] => 2011-07-14 19:09:42 
        [modified] => 2011-07-14 19:09:42 
        [active] => yes 
        [Subfirmdetailtype] => Array 
         (
          [id] => 2 
          [firmtype_id] => 1 
          [name] => Standard Deviation 
          [datatype_id] => 1 
          [created] => 2011-07-14 18:09:23 
          [modified] => 2011-07-14 18:09:23 
          [active] => yes 
          [Datatype] => Array 
           (
            [id] => 1 
            [name] => DOUBLE 
            [created] => 2011-07-14 18:14:58 
            [modified] => 2011-07-14 18:14:58 
            [active] => yes 
           ) 

         ) 

       ) 

      [2] => Array 
       (
        [id] => 3 
        [subfirm_id] => 1 
        [subfirmdetailtype_id] => 1 
        [value] => 370 
        [date] => 2011-07-11 
        [created] => 2011-07-11 12:00:00 
        [modified] => 2011-07-11 12:00:00 
        [active] => yes 
        [Subfirmdetailtype] => Array 
         (
          [id] => 1 
          [firmtype_id] => 1 
          [name] => AUM 
          [datatype_id] => 1 
          [created] => 2011-07-14 18:09:23 
          [modified] => 2011-07-14 18:09:23 
          [active] => yes 
          [Datatype] => Array 
           (
            [id] => 1 
            [name] => DOUBLE 
            [created] => 2011-07-14 18:14:58 
            [modified] => 2011-07-14 18:14:58 
            [active] => yes 
           ) 

         ) 

       ) 

     ) 

) 

私はSubFirmDetailによってグループに好きなだけsubFirmDetailTypeに応じて、最新のSubFirmDetailを示したい:

は、ここに私の出力です。ここに私は現在、私のコントローラで使用しているコードは次のとおりです。

function view($id = null) { 
       $this->Subfirm->recursive = -1; 
       $data = $this->Subfirm->find('first', array(
        'contain' => array(
         'Subfirmdetail' => array(
          'Subfirmdetailtype' => array(
           'Datatype', 
          ), 
         ), 
         'Firm' => array(
          'Firmtype', 
         ), 
        ), 
        'conditions' => array('Subfirm.id' => $id), 
       )); 
     $this->set('subfirm', $data); 
     if (!$id) { 
      $this->Session->setFlash(__('Invalid subfirm', true)); 
      $this->redirect(array('action' => 'index')); 
     } 
    } 

答えて

-1

はこれを試してみてください:

function view($id = null) { 
       $this->Subfirm->recursive = -1; 
       $data = $this->Subfirm->find('first', array(
        'contain' => array(
         'Subfirmdetail' => array(
          'Subfirmdetailtype' => array(
           'Datatype', 
          ), 
         ), 
         'Firm' => array(
          'Firmtype', 
         ), 
        ), 
        'conditions' => array('Subfirm.id' => $id), 
        'group' => 'Subfirmdetail', 
        'order' => 'date', 
       )); 
     $this->set('subfirm', $data); 
     if (!$id) { 
      $this->Session->setFlash(__('Invalid subfirm', true)); 
      $this->redirect(array('action' => 'index')); 
     } 
    } 

またはこのリンクを参照してください。

+0

グループ化を行う前に、これを日付順の列にどのように使用できますか? – jwg2s

+0

答えを更新します。 「グループ」を参照してください。 –

+0

あなたが行ったようにグループを追加することによって、モデルをグループ化するだけです。Subfirm not Subfirmdetail。エラーをスローします。 – numerical25

0

データベースにビューを作成し、条件節に含まれている配列を出力する必要がありました。同じものを試してみるために。

関連する問題