久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

CakePHP Twitter-clone:無法讓跟隨系統工作

CakePHP Twitter-clone: Can#39;t get follow-system to work(CakePHP Twitter-clone:無法讓跟隨系統工作)
本文介紹了CakePHP Twitter-clone:無法讓跟隨系統工作的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

抱歉沒有描述性的標題,但我不知道如何措辭.目前,我正在嘗試使用 cakePHP 開發 Twitter 克隆,因為我是網絡編程的新手.我用了 3 張桌子:

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:

用戶(ID,姓名)

  • id 是自動生成的 id
  • 用戶名
  • 推文(id、內容、user_id)

    tweets (id, content, user_id)

    • id 是自動生成的 id
    • content 是推文的文本
    • user_id 是發布帖子的用戶的 ID
    • 關注者(id、user_id、follow_id)

      followers (id, user_id, following_id)

      • id 是自動生成的 id
      • user_id 是執行以下操作的用戶
      • following_id 是被關注的用戶
      • 現在,幾乎一切都基本正常了,即使是follow功能也有點.但是,我想我可能錯誤地設置了模型關系.事實上,我很確定這是錯誤的.

        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.

        現在,這些是模型關系:

        Right now, these are the model relationships:

        • 用戶:有很多推文,有很多粉絲
        • 推文:屬于用戶
        • 關注者:屬于用戶
        • User: has many Tweets, has many Followers
        • Tweets: belongs to User
        • Followers: belongs to User

        我很確定 Followers 關系是錯誤的,但這就是我一直在處理的問題.現在,有效的是用戶登錄/注銷、會話、發帖、刪除您自己的帖子以及關注其他用途(然后能夠看到他們的推文).

        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).

        現在行不通的是,當我嘗試獲取我關注的人或關注我的人的列表時.問題是我不確定如何訪問這些數據.

        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.

        我想要一個屏幕,我可以在其中單擊鏈接查看我關注的所有人,然后查看他們的所有最新推文.

        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.

        例如,我相信我可以使用 find() 查詢來獲取我關注的所有人的列表,但正如您從上面的 Follower 表中看到的,該查詢僅返回以下用戶的用戶 ID追隨者和被追隨者.從這些數據中,我如何獲得他們的姓名和最新推文?

        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?

        我要進行兩次查找嗎?我可以在我的模型關系中重新定義它,以便在我的 ctp 文件中,我可以通過 php 查看并使用類似的東西:

        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:

        $this->$data['Tweet']['userID']
        $this->$data['User']['name']
        $this->$data['Tweet']['content']
        

        對不起,我不確定我是否正確地解釋了自己...

        I'm sorry, I'm not sure if I explained myself correctly...

        不過,我確實希望我的意圖很明確.任何建議表示贊賞!

        I do hope my intention is clear however. Any advice is appreciated!

        謝謝!

        推薦答案

        app/models/user.php
        
        class User extends AppModel{
              var $name = 'User';
        
              var $hasAndBelongsToMany = array(
                    'Follower' => array(
                          'className'             => 'Follower',
                          'joinTable'             => 'user_users',
                          'foreignKey'            => 'user_id',
                          'associationForeignKey' => 'child_user_id'
                    )
              )
        }
        
        app/models/follower.php
        
        class Follower extends AppModel{
              var $name     = 'Follower';
              var $useTable = 'users';
        }
        

        您必須創建一個包含 user_id 和 child_user_id 字段的表 user_users.child_user_id 將是關注者 ID,如果您愿意,您可以將其命名為關注者 ID,但如果您將來需要建立類似的關系,可能會造成混淆.

        You will have to make a table user_users with the fields user_id and child_user_id. child_user_id would be the follower ID, you could name it follower id if you want but it might be confusing if you need to make a similar relation in the future.

        試試看.

        這篇關于CakePHP Twitter-clone:無法讓跟隨系統工作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

        【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作為類名,因為它是保留的 Cake 2.2.x)
Session is lost after an OAuth redirect(OAuth 重定向后會話丟失)
Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分頁排序)
CakePHP Shared core for multiple apps(CakePHP 多個應用程序的共享核心)
Login [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登錄 [ Auth-identify() ] 始終為 false)
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命錯誤:允許的內存大小為 134217728 字節已用盡(嘗試分配 87 字節))
主站蜘蛛池模板: 精品一区国产 | 国产激情偷乱视频一区二区三区 | 亚洲美女视频 | 鸡毛片 | 亚洲一av | 日韩精品一区二区三区中文在线 | 亚洲成人精品视频 | 99re6在线 | 亚洲一区二区三区免费观看 | 国产黄色大片 | 国产午夜av片 | av中文字幕在线观看 | 国产精品欧美精品 | 久久久tv | 在线播放国产一区二区三区 | 精品视频免费在线 | 日韩欧美在线一区 | 日韩不卡一区二区三区 | 日韩精品一二三 | 成人亚洲精品 | 欧美高清一区 | 91小视频 | 久久国产精品首页 | 男女精品网站 | 欧美黑人国产人伦爽爽爽 | 国产精品视频一二三区 | 久久美国 | 欧美亚洲视频 | 夜夜撸av| 99re在线视频 | 免费久久久久久 | 超碰在线人人干 | 日韩视频在线免费观看 | 午夜ww| 国产小视频自拍 | 亚洲视频精品 | 久草www | 自拍视频在线观看 | 久久一区视频 | 日韩欧美久久精品 | 狠狠干天天干 |