Book Image

CakePHP Application Development

By : Ahsanul Bari, Anupom Syam
Book Image

CakePHP Application Development

By: Ahsanul Bari, Anupom Syam

Overview of this book

<p>Cake is a rapid development framework for PHP that uses well-known design patterns and provides a structured framework that enables PHP users at all levels to rapidly develop robust web applications, without any loss of flexibility. It means you can code faster, your code is better, and it makes writing Web 2.0-style apps a snap.<br /><br />This book offers step-by-step instructions to learn the CakePHP framework and to quickly develop and deploy web-based applications. It introduces the MVC pattern and coding styles using practical examples. It takes the developer through setting up a CakePHP development and deployment environment, and develops an example application to illustrate all of the techniques you need to write a complete, non-trivial application in PHP. It aims to assist PHP programmers to rapidly develop and deploy well-crafted and robust web-based applications with CakePHP.</p>
Table of Contents (18 chapters)
CakePHP Application Development
Credits
About the Authors
About the Reviewer
Preface
Index

Creating a User Page


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.

Time for Action

  1. First, lets add an action to the Users controller, named show(), 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...