Thanks a lot Ratty and cricket, couldn't have managed it without your help.
For other people looking at this, I managed it this way to prevent multiple
sessions reload, seems to work for now :
*In UsersController, in the view function :*
$followers = Set::extract('/Follower/id', $user);
$this->set('followers', $followers);
*In User/view.ctp :*
<?php
if ($user['User']['id'] == $this->Session->read('Auth.User.id')) {
echo("<a class='btn disabled'>This is you</a>");
} elseif (in_array($this->Session->read('Auth.User.id'), $followers)) {
echo $this->element('unfollow');
} else {
echo $this->element('follow');
}
?>
*Elements :*
Follow.ctp :
<?php
echo $this->Form->create('User', array(
'class' => 'form-inline',
'action' => 'follow',
'inputDefaults' => array(
'label' => false,
) ));
echo $this->Form->input('UsersUsers.follower_id',array(
'type' => 'hidden',
'value' => $this->Session->read('Auth.User.id'),
));
echo $this->Form->input('UsersUsers.following_id',array(
'type' => 'hidden',
'value' => $user['User']['id'],
));
echo ("<input type='submit' class='btn btn-success' value='Follow'>"); ?>
</form>
Only need to code the "unfollow" form now I guess, wich lead me to my
initial question I guess, how can I locate and delate the database entry ?
Should look like this for example:
id follower_id following_id
X 1 3
Le jeudi 14 juin 2012 14:40:16 UTC+2, JonStark a écrit :
>
> I have a table with the following fields :
>
> id follower_id following_id
>
> So when a user clicks "follow" on an other user's profile, an entry like
> this is created :
>
> 15 1 3
>
> meaning user with id 1 follows user with id 3.
>
> If user 3 follows 1, then an entry like
>
> 16 3 1
>
> is created.
>
> But, in order to prevent users for following many time a same user,
> leading to entry such as :
>
> 17 3 1
> 18 3 1
> 19 3 1
>
> and so on, I want to replace "follow" by "unfollow" if the entry is
> already saved.
>
> So my question is : how can i "scan" the table to check if an entry as
> both X as follower_id AND Y as following_id ?
>
> Thanks a lot.
>
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php