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 7805555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:15:57+00:00 2026-06-02T02:15:57+00:00

I am developing an application in YII modules based Need to restrict users on

  • 0

I am developing an application in YII modules based

Need to restrict users on certain actions as well as on entire module

I was able to restrict the users using 'expression' + callback in rules but now I want to use the same callback function for two different actions i.e. I have a callback function which I want to get the parameter value and depending on that evaluate what action to perform, here is what I have done as yet

public function accessRules()
    {
        return array(
            array('allow',  // allow all users to perform 'index' and 'view' actions
                'actions'=>array('index'),
                'users'=>array('*'),
                'expression'=>array($this, "checkAccessRule"),
            ),
            array('allow',  // allow all users to perform 'index' and 'view' actions
                'actions'=>array('login'),
                'users'=>array('?'),
            ),
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions'=>array('view','create','update','admin','delete'),
                'users'=>array('@'),
                'expression'=>array($this, "checkAccessRule"), 
            ),
            array('deny',  // deny all users
                'users'=>array('*'),

            ),
        );
    }

the callback function

function checkAccessRule($op){ 
        if($op == 1){
            if(in_array($this->module->getName(), Yii::app()->user->getState("companyModules")))
                return true;
            return false;
        }elseif($op == 2){
            if((Yii::app()->user->getState("user_role") == 1) && (in_array($this->module->getName(), Yii::app()->user->getState("companyModules"))))
                return true;
            return false;
        }
    }

unable to get this ‘$op’ from the callback if i send it 'expression'=>array($this, "checkAccessRule(1)"),

any help would be appreciated

  • 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-02T02:15:58+00:00Added an answer on June 2, 2026 at 2:15 am

    That won’t work, when you state the function name it will be called via Yii as a string so the (1) will be taken as part of the function name. Lucky for you, the expression parameter accepts an anonymous function too (function(){}). so:

    public function accessRules()
    {
        return array(
            array('allow',  // allow all users to perform 'index' and 'view' actions
                'actions'=>array('index'),
                'users'=>array('*'),
                'expression'=>function(){$this->checkAccessRule(1)},
            ),
            array('allow',  // allow all users to perform 'index' and 'view' actions
                'actions'=>array('login'),
                'users'=>array('?'),
            ),
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions'=>array('view','create','update','admin','delete'),
                'users'=>array('@'),
                'expression'=>function(){$this->checkAccessRule(1)},, 
            ),
            array('deny',  // deny all users
                'users'=>array('*'),
    
            ),
        );
    }
    

    Should work.

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

Sidebar

Related Questions

We've been developing a web application (PHP, using the Yii PHP framework) that is
I am developing application application using C++ VS 2008. Now I need to either
I am developing web application using Yii framework. currently i am in the process
I am developing application where i need to get users phone number. Now i
I'm developing application using backbone.js & jquery. I have following code in model: runReport:
What is difference in developing applications using .Net Framework, Asp.net and developing application in
Currently developing an application using the newest version of symfony, obtained through PEAR. This
I am developing application using phonegap in eclipse for android .I have created folder
I'm developing application with Qt Embedded and run it in linux framebuffer. I need
I am developing application using Entity Framework. When i'm in debugging mode my test

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.