-
Book Overview & Buying
-
Table Of Contents
Yii Application Development Cookbook - Second Edition - Second Edition
In many cases, we need to filter the incoming data or perform some actions based on this data. For example, with custom filters, we can filter visitors by IP, force users to use HTTPS, or redirect the user to an installation page prior to using the application. Yii has two built-in usable filters. First is CInlineFilter, which allows using the controller method as a filter, and the second (the one we will focus on) is CAccessControlFilter, which allows controlling access to various controller actions.
In this recipe, we will implement the following:
Limiting access to the controller action to authorized users only
Limiting access to the controller action to specified IPs
Limiting access to specific users
Limiting access for users of a browser specified; in this case, we will also show the custom message
Create a fresh application by using yiic webapp.
Create protected/controllers/AccessController.php as follows:
<?php class AccessController extends CController...
Change the font size
Change margin width
Change background colour