shxfee
shxfee

Reputation: 5306

Is there an Auth Component's helper in Cakephp 2.x?

Is there an Auth Component's helper in Cakephp 2.x?
Currently I just pass the $Auth object to the view in the AppController like so:

$this->set('Auth', $this->Auth);

I searched around but there doesnt seem to be a helper available by default. I need some of the functions of the Auth component in the views like Auth::loggedIn().

help?

Upvotes: 2

Views: 2825

Answers (2)

AD7six
AD7six

Reputation: 66349

There is no need for an AuthHelper

The AuthComponent::user function can be called statically:

if (AuthComponent::user()) {
    // user is logged in
}

Or since it just reads from the session the same information can also be found via the session (component/helper/class):

if ($this->Session->read('Auth.User')) {
    // user is logged in
}

It is not a good idea, or required to pass the Auth component (or any component) to the view.

Upvotes: 6

bish
bish

Reputation: 3419

The Auth Component still exists: http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html

Upvotes: 0

Related Questions