はじめまして!
現在CakePHPを活用して、自分がフォローしているユーザーのコメントがタイムラインのような形式で閲覧できる機能を実装しようと考えています。
php
1//CommentsController.php 2 public function index() { 3 4$user_id = AuthComponent::user('id') //自分のユーザーID 5 6$follow = $this->Follow->find('first', array('conditions' => array('from_id' => $user_id))); //自分がフォローしている一人のユーザー 7 8 $this->set('comments', 9 $this->Comment->find('all', array( 10 'conditions' => array('Comment.whom' => $follow['Follow']['to_id']) //今のコードでは一人のユーザーしか含まれない 11 )) 12 ); 13 } 14
そこで、上記のコードを実装することでフォローしているユーザーのコメントをcommentsにセットすることは出来たのですが、今のままでは一人のフォローユーザーのコメントしかセットできません。
php
1$follow = $this->Follow->find('first', array('conditions' => array('from_id' => $user_id))); //自分がフォローしている一人のユーザー
上記のコードをfind(all)に変更した場合、
php
1$this->set('comments', 2 $this->Comment->find('all', array( 3 'conditions' => array('Comment.whom' => $follow['Follow']['to_id']) //今のコードでは一人のユーザーしか含まれない 4 )) 5 );
の部分を具体的にどのように変更すればよいでしょうか?
何かお分かりの方は、是非ともご教授のほどよろしくお願い申し上げます。
補足:
(followsテーブル)
id 主キー
from_id (フォローする)ユーザーID
to_id (フォローされる)ユーザーID
from_idのユーザーが、to_idのユーザーをフォローする形式
(commentsテーブル)
id 主キー
comment コメント
whom コメントを投稿したユーザーID
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/11/30 09:00