In this section, we will create a user page that will be showing the questions posted by a particular user. In addition to that, the page will also contain information about the user such as the number of questions posted by the user, the number of answers given, and the user's joining date. Lastly, we will be adding a link so that the user can easily check their own page.
First, lets add an action to the
Users
controller, namedshow()
, for the user page. Add the following code to it:<?php class UsersController extends AppController { var $name = 'Users'; var $components = array('Email'); function signup(){ ... } ... function show($id = null) { if (!$id) { $this->Session->setFlash('Invalid User.'); $this->redirect(array('controller' => 'questions', 'action'=>'home')); } $this->User->recursive = 2; $this->set('user', $this->User->find(array('User.id' => $id), array('id', 'username', 'created'))); $this->User->Answer...