How to set default action dynamically in Yii -


I want to change the default action of a controller depending on which user is logged in. Ex My site has two users: Publisher and Author and I want to set the publisher's action as a default work in the form of a publisher, and also for the author.

What should I do? When can I check my roles and set up my related tasks?

Another way to do this is to some extent in its controller like this:

  & lt ;? Php class extends the MyAwesomeController controller {// or spreads to CController based on your code init () {parent :: init (); // There is no need for this call if your parents do not have anything init (), if (array_key_exists ('RolePublisher', Yii :: app) - & gt; authManager- & gt; getRoles (Yii :: app) - & gt; user- & gt; ID) $ this- & gt; Default action = 'publisher'; // Your action name and name (array_key_exists ('RoleAuthor', Yii :: app) - & gt; authManager- & gt; getRoles (Yii: app () - & gt; User- & gt; ID) $ $ - & gt; DefaultAction = 'Author'; // your action name} // ... the rest of your code}? & Gt;   

See if the 'array' = & gt; The CAuthItem object will be the format of , which is why I Array_key_exists () .

If you do not know, then the name of the action will be the name only without the part of the action, for example if you have public function action Publisher () {...} Then the name of the action should be: publisher .

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -