user
user

Reputation: 1759

Navigate hyperlink in yii

I have created a hyperlink in my admin.php page as follows:

echo CHtml::Link('savepage','save');

This would mean that on clicking the given hyperlink it should perform the code given in actionSave() of my controller page.

Here is my code for controller-

actionSave()
{
echo 'hi';
}

But it gives an error- Error 403 You are not authorized to perform this action.

If I change the "save" to "index" in my admin.php file, it is working well. How can I navigate to write my custom code for the link?

Upvotes: 0

Views: 47

Answers (1)

Rafay Zia Mir
Rafay Zia Mir

Reputation: 2116

in your controller you have to change the access rules. You have to register this action first.Index works for you because it is registered already.

public function accessRules()
    {
        return array(
            array('allow',  // allow all users to perform 'index' and 'view' actions
                'actions'=>array('index','view'),
                'users'=>array('*'),
            ),
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions'=>array('create','update','Save'),
                'users'=>array('@'),
            ),
            array('allow', // allow admin user to perform 'admin' and 'delete' actions
                'actions'=>array('admin','delete'),
                'users'=>array('admin'),
            ),

        );
    }

Upvotes: 0

Related Questions