www.webdeveloper.com
Results 1 to 4 of 4

Thread: how to make friend system using cakephp?

  1. #1
    Join Date
    Jul 2013
    Posts
    2

    how to make friend system using cakephp?

    hey guys i am new in cakephp,this is my question.
    how i make a friend system in my project.
    I'll try to make a social networking site..

    anyone does help me?

    thaks..

  2. #2
    Join Date
    Sep 2013
    Posts
    221
    Try this.
    The below link can help you to understand cakephp:

    http://www.packtpub.com/sites/defaul...tion-logic.pdf

    The below code will help you to Add a friend feature in CakePHP:

    The friendships table should have following columns:

    id Integer
    user_from (the user who requested friendship)
    user_to (the user who accepted friendship)
    created (optional to track when your friendship started)
    Then you need to create proper Model relation.

    class User extends AppModel {
    ...
    var $hasMany = array(
    'UserFrom'=>array(
    'className'=>'Friendship',
    'foreignKey'=>'user_from'
    ),
    'UserTo'=>array(
    'className'=>'Friendship',
    'foreignKey'=>'user_to'
    )
    );
    var $hasAndBelongsToMany = array(
    'Friendship' => array(
    'className' => 'User',
    'joinTable' => 'friendships',
    'foreignKey' => 'user_from',
    'associationForeignKey' => 'user_to'
    );
    ...
    }

    class Friendship extends AppModel {
    ...
    var $belongsTo = array(
    'UserFrom'=>array(
    'className'=>'User',
    'foreignKey'=>'user_from'
    ),
    'UserTo'=>array(
    'className'=>'User',
    'foreignKey'=>'user_to'
    )
    )
    ...
    }

    This way you are defining 2 relation in each model. Run bake script to build your controllers and views. Then in your code you can use something like this:

    $this->User->UserFrom->find('all',
    array(
    'conditions'=>array('user_from'=>1),
    'contain'=>array('UserTo')
    )
    );

    Hope this helps you.
    strad solutionswww.stradsolutions.com

  3. #3
    Join Date
    Jul 2013
    Posts
    2
    but how about in my view ?

  4. #4
    Join Date
    Sep 2013
    Posts
    221
    The whole code is for view page only except the table values.
    strad solutionswww.stradsolutions.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles