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

Integrating Authentication: Controllers


We continue our effort to integrate the User model and the authentication process into our database. This section shows the changes that are required in the controllers:

Time for Action

  1. Go into the directory /app and create a new file. Name the file app_controller.php. Add the following code to it and save:

    <?php
    class AppController extends Controller {
    }
    ?>
    
  2. Now, add the Auth component to the newly created AppController class:

    <?php
    class AppController extends Controller {
    var $components = array('Auth');
    }
    ?>
    
  3. Add the beforeFilter() function to the AppController class, with the following code:

    <?php
    class AppController extends Controller {
    var $components = array('Auth');
    function beforeFilter(){
    $this->Auth->loginRedirect = array('controller' => 'questions', 'action' => 'home');
    $this->Auth->logoutRedirect = array('controller' => 'questions', 'action' => 'home');
    $this->Auth->allow('signup', 'confirm', 'home...