I have not used Doctrine only Propel but first of all, try to avoid using
Doctrine Criteria type commands in your action. In Propel I would create a
method in my model class like:

public static function getUserFriends($user_id)
{
  $criteria = new Criteria();
  $criteria->add(self::USER1, $user_id);
  $result = self::doSelect($criteria);

  $friends_array = array();
  foreach ($result as $record)
  {
    $friends_array[] = $record->getUser2();
  }

  return $friends_array;
}

In my action would be :

$this->data = FriendReference:: getUserFriends($user_id);

Therefore its very nicely encapsulated, 100% reusable, and if I ever need to
change the criteria of what data is returned I don't need to even touch my
action.

On Mon, Nov 23, 2009 at 2:29 PM, tirengarfio <[email protected]> wrote:

>
> On 23 nov, 06:51, Gareth McCumskey <[email protected]> wrote:
>
> > Does it matter?
>
> Maybe yes...
>
> I need an array to search on it in the view. For that, i have written
> this code in the action:
>
> // This fetches the friends of the user with the ID '1'.
> $this->friend_list = Doctrine::getTable('FriendReference')
>   ->createQuery('a')
>   ->select('a.user2')
>   ->where("a.user1 LIKE ?", '1')
>   ->execute();
>
> // "data" stores the friends of the user with the ID '1'.
> $this->data = $this->friend_list->toArray();
>
>
> And this is my code of the view:
>
> // "in_array" search if a user is in the friends array.
> $a = (int)in_array($member->getId(), $data);
>
>
> Javi
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "symfony users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<symfony-users%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/symfony-users?hl=.
>
>
>


-- 
Gareth McCumskey
http://garethmccumskey.blogspot.com
twitter: @garethmcc

--

You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=.


Reply via email to