Not able to call the action inside a controller. But if i use the same action inside other controller, I am able to call that action. Help me out.
Not able to call the action inside a controller. But if i use the same action inside other controller, I am able to call that action. Help me out.
You need to post more details and the specific code you’re using.
Local action can be called like
$this->index
from other controller you know… already u did
Please copy your code what you have tried … it will be helpful to solve
This is my controller :
class AdminController extends Controller
{
public $layout='//layouts/admin';
public $menu = array();
public function actions()
{
return array(
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xEBF4FB,
),
);
}
/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
);
}
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view','discovery'),
'users'=>array('*'),
),
);
}
public function actionDiscovery()
{
$this->render('//features/discovery');
}
}
When I type my url like www.xxxx.com/admin/discovery , the above method is not getting called. If I copy the above action inside another controller, it is working
This can be caused by url misconfiguration or existing ‘admin’ module.
This is my controller :
class AdminController extends Controller
{
public $layout='//layouts/admin';
public $menu = array();
public function actions()
{
return array(
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xEBF4FB,
),
);
}
/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
);
}
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view','discovery'),
'users'=>array('*'),
),
);
}
public function actionDiscovery()
{
$this->render('//features/discovery');
}
}
When I type my url like www.xxxx.com/admin/discovery , the above method is not getting called. If I copy the above action inside another controller, it is working
No new actions under that controller is working. But the actions which are already present(old ones) are working properly.
Do I have to add the url somewhere to make it work ?
Hi ,
There is a logical help .
If you are allowing all users , then why do you need filters and accessRules methods … PLEASE REMOVE…
then automatically everything will work
I hope cheers
Hi ,
There are few actions which are restricted and thats why I have used filters.
Adding the action to all users dint help.
Below code says that, allow all users even without login
@ refers to only login users
you are telling only by your mouth… u r restricting some person… but in coding nothing like that …
I think u should read documentation
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view','discovery'),
'users'=>array('*'),
),
I did not add that piece of code. Here it is :
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('create','update', 'admin','delete'),
'users'=>Yii::app()->user->adminUsers(),
)
Found the solution. For the link like index/admin/discovery 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',
),
),
);
Thanks for your comments.