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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:39:58+00:00 2026-06-14T20:39:58+00:00

I have an if statement in a cakePHP app and I cant work out

  • 0

I have an if statement in a cakePHP app and I cant work out why its not doing what I would expect.

public function isAuthorized($user) {         
        if ($user['role'] === 'admin'){
            return true;
        }
        if ((in_array($this->action, array('view', 'index')))&&($user['role'] === 'senior' || 'junior')) {

          return true;
        }
        return false;
       }

I would expect that if there is a user with the role “agent” it would deny all actions.

If I use this instead everthing is rosey, just not sure why its not checking both arguments before setting the boolean to True?

public function isAuthorized($user) {
        if ($user['role'] === 'admin'){
            return true;
        }
        if ($user['role'] == 'agent'){
            return false;
        }
        if (in_array($this->action, array('edit', 'add', 'delete'))) {
            if ($user['role'] == 'senior' || 'junior') {
                return false;
            }

        }
        return true;
    }

Any Ideas?
Thanks

  • 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-14T20:39:59+00:00Added an answer on June 14, 2026 at 8:39 pm

    One of your test is wrong and always evaluates to true.

    if($user['role'] === 'senior' || 'junior'){
      //will always be true 
    }
    

    because you are evaluating 'junior' as a boolean, which is true in PHP.

    Your condition should be:

    if($user['role'] == 'senior' || $user['role'] == 'junior'){
      ...
    }
    

    Note that you could also write it like this:

    if(in_array($user['role'], array('senior', 'junior'))){
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a statement such as below but its padded out to do 1000
In my Jobs controller I have this statement under the index() function: $this->Job->find('all', array('conditions'
I am writing a CakePHP 1.2 app. I have a list of people that
I have a CakePHP app which I have been developing on a remote server.
i have a statement: on error go to label however i would like to
I have a CakePHP 2.0 app that uses the AuthComponent with User model to
I have this statement: return *local_stack_var2++ + 42; Would these be the proper steps
I have this statement: pn = r.notFound == true ? Not currently assigned :
I have the following tables for my CakePHP app that allows friendships between users:
if i have statement: $a = 1; $b = 2; $c = 3; if($a

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.