Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8219555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:12:30+00:00 2026-06-07T13:12:30+00:00

i want to change default action of a controller depends on which user is

  • 0

i want to change default action of a controller depends on which user is logged in.
Ex. There are two users in my site : publisher and author and i want to set publisher action as default action when a publisher is logged in, and same for author.

what should i do? when can I check my roles and set their relevant actions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:12:34+00:00Added an answer on June 7, 2026 at 1:12 pm

    Another way to do this would be setting the defaultAction property in your controller’s init() method. Somewhat like this:

    <?php
    class MyAwesomeController extends Controller{ // or extends CController depending on your code
        public function init(){
            parent::init(); // no need for this call if you don't have anything in your parent init() 
    
            if(array_key_exists('RolePublisher', Yii::app()->authManager->getRoles(Yii::app()->user->id)))
                $this->defaultAction='publisher'; // name of your action
    
            else if (array_key_exists('RoleAuthor', Yii::app()->authManager->getRoles(Yii::app()->user->id)))
                $this->defaultAction='author'; // name of your action
        }
        // ... rest of your code
    }
    ?>
    

    Check out CAuthManager’s getRoles(), to see that the returned array will have format of 'role'=>CAuthItem object, which is why i’m checking with array_key_exists().

    Incase you don’t know, the action name will be only the name without the action part, for example if you have public function actionPublisher(){...} then action name should be: publisher.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to change the default homepage (which appears on typing http://myserverip:8080) and redirect
When Dropdown is opened - I want to change default color of it. I
I want to change the default arguments passed to a Ruby function. For example,
I want to modify / change the way the floatformat works. By default it
Global.asax route values routes.MapRoute( Default, // Route name {controller}/{action}/{id}, // URL with parameters new
I want to be able to change the default mapping of actions with RESTful
I want to change the default route on my application to use an optional
i want to change the default route in RoR to what i want: consider
i want change the content of a UITableView when i change a button, how
I want change following javascript code to jquery code, How is it? With done

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.