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

  • Home
  • SEARCH
  • 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 6780411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:30:09+00:00 2026-05-26T16:30:09+00:00

I’m having difficulty understanding what’s going on here class AppController extends Controller { …

  • 0

I’m having difficulty understanding what’s going on here

class AppController extends Controller {
...
public function beforeFilter() {
    $user = $this->Auth->user();
    if (!empty($user)) {            
        Configure::write('User', $user[$this->Auth->getModel()->alias]);
    }
}
...
}

In my example…

  1. $user = Array ( [id] => 1 [username] => user [active] => 1 [email] => user@site.com )

  2. $this->Auth->getModel()->alias = ‘User’ (string)

  3. $user[$this->Auth->getModel()->alias] = Array ( [id] => 1 [username] => user [active] => 1 [email] => user@site.com )

My questions:

  1. How are $user[‘User’] and $user the same thing? It looks to me $user is an associative array with keys id, username, active, and email. I’m not sure how using the key ‘User’ works.

  2. Could someone explain the “::” syntax and what Configure::write(‘User’, …) does and how to access this ‘User’ variable (probably has some conventional term for it..). I’m finding that Configure::read(‘User’) retrieve this information. Is this right?

  3. Finally.. I’m confused between two terms User (model as in $this->User->create() to create a new user) and User (from Configure::write(‘User’,…)). They are not the same things, are they?

  • 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-05-26T16:30:10+00:00Added an answer on May 26, 2026 at 4:30 pm

    You can use different models together with the AuthComponent. The default is User, but you may make it Member, Admin or whatever else your user models are called. Calling $this->Auth->user() returns an array with that primary name attached to it, like:

    array(
        'Admin' => array(
            'id' => ...
            ...
        )
    )
    

    (I suspect you’re debugging your $user variable wrong there.)

    The only thing that block of code does is to write the user details into the Configuration (just a place to store values) without this intermediate Admin key. I guess this is so any piece of code anywhere can get at the current user details without having to worry about whether it’s $user['User'] or $user['Admin'] or something else. Instead you can simply use Configure::read('User') or Configure::read('User.id') or Configure::read('User.name') etc.

    The choice of the name User in Configure::write('User', ...) is entirely arbitrary. You could use anything there, it has no predefined meaning.

    BTW, if it’s just the controller, you can get the details of the current user without worrying about what the user model is called using $this->Auth->user('name') (to get the name, for example).

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need to clean up various Word 'smart' characters in user input, including but
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I need a function that will clean a strings' special characters. I do NOT
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.