Search code examples
phpcakephpsocial-networking

Individual Profile / User Page in CakePHP


I am in the process of building a webapp in cakePHP where once a user has signed up they would have their own profile page that can be seen by other members. Ideally I would like a nice url e.g. www.website.com/davejones but I can settle for something that was like www.website.com/uid=235325.

What would be the best way of going about this?


Solution

  • Basically you would just add a profile method to your UsersController that takes the user id/username as a parameter and then just serve that page.

    class UsersController extends AppController {
    
        public function profile($uid) {
            $data = $this->User->findById($uid);
            $this->set(compact('data'));
        }
    
    }
    

    Would make all data of that user (incl. associated data, if your models setup properly) go into the $data variable that you can call from your view. Do with it what you want there.