Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to accessing the Auth Componenet from a view in CakePhp

    • 0
    • 2
    • 4
    • 0
    • 0
    • 0
    • 0
    • 0
    • 152
    Comment on it

    In CakePHP, you may want to use the Auth component to check if a user is currently logged-in to the system. you cannot access the Auth component from a view. So doing something like this in a view

    $user = $this->Auth->user

    This will Generate an error in CakePHP since the Auth component cannot be accessed in a view Fortunately, there is a way to access the Auth component from a view you can simply use CakePHP Session Component. The Session component stores the the Auth component. So, if you wanted to know if a user is logged-In into the system, you can do the following:

    $user = $this->Session->read('Auth.User');
    if ($user){
    // do something 
    }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: