Book Image

Yii Project Blueprints

By : Charles R. Portwood ll
Book Image

Yii Project Blueprints

By: Charles R. Portwood ll

Overview of this book

Table of Contents (15 chapters)
Yii Project Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating the controllers


Now that we have registered our application with Yii and defined our custom routes, we can start working on our controllers. First, we should work on our DashboardController component so that our controllers automatically inherit some common behaviors. The steps are as follows:

  1. Within our DashboardController.php component, we should first define our accessRules() method. This will ensure that only administrators have access to the dashboard:

    public function filters()
    {
       return array(
          'accessControl'
       );
    }
    
    public function accessRules()
    {
       return array(
          array('allow',  // allow authenticated admins to perform any action
             'users'=>array('@'),
          ),
          array('deny',  // deny all users
             'users'=>array('*'),
             'deniedCallback' => array($this, 'actionError')
          ),
       );
    }
  2. Next, we'll define the default layout that we'll want to use throughout the module:

    public $layout='default';
  3. Then, we'll create a custom error action...