Re: Check table for a particular entry

2012-06-18 Thread lowpass
On Sun, Jun 17, 2012 at 2:50 PM, JonStark wrote: > Ok, almost there, just need a little help with Set:: > > I'm using > > Set::extract('/Follower/UsersUser', $user) > > to get all the data from the association table of a given user, wich when > debugged produces an array like this one : > > array(

Re: Check table for a particular entry

2012-06-18 Thread JonStark
Damn, really stuck with this, any idea ? Many thanks ! 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

Re: Check table for a particular entry

2012-06-17 Thread JonStark
Ok, almost there, just need a little help with Set:: I'm using Set::extract('/Follower/UsersUser', $user) to get all the data from the association table of a given user, wich when debugged produces an array like this one : array( (int) 0 => array( 'UsersUser' => array(

Re: Check table for a particular entry

2012-06-16 Thread lowpass
On Sat, Jun 16, 2012 at 12:43 PM, JonStark wrote: > > 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                

Re: Check table for a particular entry

2012-06-16 Thread JonStark
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->s

Re: Check table for a particular entry

2012-06-16 Thread lowpass
On Sat, Jun 16, 2012 at 6:44 AM, JonStark wrote: > I tried this, it's actually clever, but there's a flaw I guess. > > Since the extract is done when logging in, the follow link will still appear > for all the users you will follow after, and disappear only when re-logging > in. Just update each

Re: Check table for a particular entry

2012-06-16 Thread JonStark
I tried this, it's actually clever, but there's a flaw I guess. Since the extract is done when logging in, the follow link will still appear for all the users you will follow after, and disappear only when re-logging in. Le jeudi 14 juin 2012 14:40:16 UTC+2, JonStark a écrit : > > I have a tabl

Re: Check table for a particular entry

2012-06-15 Thread lowpass
My bad. I wrote that example without thinking about it. Yes, it would have to be in the controller because AuthComponent isn't available in a view, of course. What you could do is extract the following & follower IDs in the login action and store them in the session. That's where Auth keeps the da

Re: Check table for a particular entry

2012-06-15 Thread JonStark
OK, I figured out this should go into the controller. But How can I use this function to alternate between two buttons follow / unfollow *in the view *? public function checkIfFollow() { if (in_array(Set::extract('/Following/id', $this->Auth->user()), $id)) { // stop follow } else { //

Re: Check table for a particular entry

2012-06-15 Thread JonStark
This returned : *Notice* (8): Undefined property: View::$Auth [*CORE/Cake/View/View.php*, line *806*] *Fatal error*: Call to a member function user() on a non-object in * /app/View/Users/view.ctp* on line *41* * * with ths code: Auth->user()), $id)) { echo("following alread

Re: Check table for a particular entry

2012-06-14 Thread lowpass
On Thu, Jun 14, 2012 at 1:41 PM, JonStark wrote: > From what I understand, this method extracts the ID of the followed users > from the AUTH data right ? I thought the array you posted was the output of $this->Auth->user() but maybe i misread that. When a given User logs in, their data is kept in

Re: Check table for a particular entry

2012-06-14 Thread JonStark
>From what I understand, this method extracts the ID of the followed users from the AUTH data right ? Can set::extract work with the array produced when finding/viewing an user ? Le jeudi 14 juin 2012 19:31:27 UTC+2, cricket a écrit : > > You could extract all of the "Following" IDs. > > $follo

Re: Check table for a particular entry

2012-06-14 Thread lowpass
You could extract all of the "Following" IDs. $following_ids = Set::extract('Folllowing/id', $this->Auth->user()); Or: if (in_array(Set::extract('Folllowing/id', $this->Auth->user()), $some_user_id) { // already following } else { ... } On Thu, Jun 14, 2012 at 10:03 AM, JonStark wrote: >

Re: Check table for a particular entry

2012-06-14 Thread lowpass
On Thu, Jun 14, 2012 at 9:59 AM, Steve Found wrote: > Hmmm...  I'm not convinced that Cake will handle a HABTM relationship with a > model to itself very well as the table alias will be the same name in the > SQL it generates. No, that's exactly the way to do it. Cake will use the alias -- not th

Re: Check table for a particular entry

2012-06-14 Thread JonStark
To match if* 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

Re: Check table for a particular entry

2012-06-14 Thread JonStark
I was wondering if there was a way to scan the array produced when looking at an user, in the section "Follower", to match id any ID == Auth.user.id, since arrays are like this : */app/Controller/UsersController.php* (line *28*) array( 'User' => array( 'password' => '***

Re: Check table for a particular entry

2012-06-14 Thread Steve Found
Hmmm... I'm not convinced that Cake will handle a HABTM relationship with a model to itself very well as the table alias will be the same name in the SQL it generates. I would try creating a class Other.php as : class Otheruser extends AppModel { public $name = 'Otheruser'; public $us

Re: Check table for a particular entry

2012-06-14 Thread JonStark
This is my User model : class User extends AppModel { > public $name = 'User'; > > public $hasMany = 'Post'; > > public $hasAndBelongsToMany = array( > 'Following' => array( > 'className' => 'User', > 'joinTable' => 'users_users', > 'forei

Re: Check table for a particular entry

2012-06-14 Thread Steve Found
Can you post what your models look like please ? On 14/06/12 14:00, JonStark wrote: Assuming this is a HABTM relationship, you would just need to query the following model then look in the follower relationship to see if the users ID exists. YES this is exactly what I want to achieve, but I'm

Re: Check table for a particular entry

2012-06-14 Thread JonStark
Assuming this is a HABTM relationship, you would just need to query the following model then look in the follower relationship to see if the users ID exists. YES this is exactly what I want to achieve, but I'm really new to PHP/Cake, I can't figure out how to check this. My user array looks l

Re: Check table for a particular entry

2012-06-14 Thread Steve Found
You would probably be better off checking if the entry already exists BEFORE creating a duplicate, then deleting it ? That way you could have a 'Follow' if the entry does not exist and an 'Unfollow' if it does exist. Assuming this is a HABTM relationship, you would just need to query the fol

Check table for a particular entry

2012-06-14 Thread JonStark
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 orde