I'm new to yii.
I've created a controller called CatalogController. I want to create a custom action called actionClear(). I've followed steps from documentation and searching on-line but when I navigate to catalog/clear, it redirects back to homepage of site. I don't know what other steps I should be taking.
I've done the following so far:
in CatalogController:
public function actionClear() {
$dataProvider=new CActiveDataProvider('Catalog');
$this->render('clear',array('dataProvider'=>$dataProvider));
}
overridden rules() method in controller:
public function actions()
{
return array(
'clear'=>'application.controllers.post.ClearAction',
);
}
a new custom action under protected/controllers/post
class ClearAction extends CAction
{
public function run()
{
echo 'fart';die;
}
}
Any help would be greatly appreciated.
Did you try the url index.php?r=catalog/clear
or jus index.php/catalog/clear
?
By default in yii only the first one will work. For the second one you need to activate it in the url manager:
In your config file edit the url manager as follow:
array(
......
'components'=>array(
......
'urlManager'=>array(
'urlFormat'=>'path',
),
),
);
Source: The Yii guide
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.