Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP Twitter-clone: Can't get follow-system to work
    text
    copied!<p>Sorry for the non-descript title, but I'm not sure how to phrase it. Currently, I am trying my hand at developing a Twitter clone with cakePHP, since I'm new to web programming. I have gone with 3 tables:</p> <blockquote> <p>users (id, name)</p> </blockquote> <ul> <li>id is the auto-generated id</li> <li>name of the user</li> </ul> <blockquote> <p>tweets (id, content, user_id)</p> </blockquote> <ul> <li>id is the auto-generated id</li> <li>content is the text of the tweet</li> <li>user_id is the id of the user that made the post</li> </ul> <blockquote> <p>followers (id, user_id, following_id)</p> </blockquote> <ul> <li>id is the auto-generated id</li> <li>user_id is the user who is doing the following</li> <li>following_id is the user that is being followed</li> </ul> <p>Now, almost everything is basically working, even the follow function somewhat. However, I think I may have set up the model relationships wrong. In fact, I'm pretty sure it's wrong.</p> <p>Right now, these are the model relationships: </p> <ul> <li><strong>User:</strong> has many Tweets, has many Followers </li> <li><strong>Tweets:</strong> belongs to User</li> <li><strong>Followers:</strong> belongs to User</li> </ul> <p>I'm pretty sure the Followers relationship is wrong, but that's what I've been working with. Right now, what works is the user login/logout, sessions, posting, deleting your own posts, and following other uses (and then being able to see their tweets). </p> <p>What doesnt work right now is when I try to get a list of people I'm following or people that is following me. The problem is I'm not sure how to access that data.</p> <p>I want to have a screen where I can click on a link to see all the people I'm following and then see all of their latest tweets.</p> <p>For example, I believe I can do a use a find() query to get a list of all the people I'm following, but as you can see from the Follower table above, that query only returns the user IDs of the follower and followee. From that data, how do I get access to their names and latest tweet?</p> <p>Do I do two lookups? Is it something I can redefine in my model relationships, so that when in my ctp file, I can just php look through and use something like:</p> <pre><code>$this-&gt;$data['Tweet']['userID'] $this-&gt;$data['User']['name'] $this-&gt;$data['Tweet']['content'] </code></pre> <p>I'm sorry, I'm not sure if I explained myself correctly...</p> <p>I do hope my intention is clear however. Any advice is appreciated!</p> <p>Thank you!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload