Difference between #4 and #10 of
How to use a Widget as an Action Provider


Title unchanged

How to use a Widget as an Action Provider

Category unchanged


Yii version unchanged

Tags unchanged

Widgets, CAction

Content changed

##What is an Action Provider Widget? As written on the [API docs](http://www.yiiframework.com/doc/api/1.1/CWidget#actions-detail "actions"): An Action Provider Widget is a widget that has declared several actions by using its '**public static function actions()**'. After, a Controller can easily import all its declared actions on its '**public function actions()**'. ##Step 1: Create the Action Class For the sake of the article we need to creatinge an action named **getData** that is supposed to be shared among the whole project and saved with the name **getData.php** on our **protected/components/actions** folder.

// we point to the location where the provider
// is.
'application.components.testProvider',       'getData'=>array(      // property1 must be a public variable     // on getData CAction class       'property1'=>'value1',
##Access Rules
Also, if you have implemented the accessRules method inside the controller, then you'll need to make sure that you _allow_ the action provider in the accessRules method, otherwise you will receive 404 error when trying to view the page. Something like this will do the trick:
public function accessRules()
        return array(
                'actions' => array('test.getData'),
                'users' => array('*'),
',  ),
'users' => array('*'),
);     }
24 0
Viewed: 51 414 times
Version: 1.1
Category: How-tos
Written by: Antonio Ramirez
Last updated by: stinkytofu
Created on: Feb 18, 2011
Last updated: 4 years ago
Update Article


View all history