-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AuthComponent static loggedIn #2390
Comments
Can you describe one of those instances that isn't served by:
? |
I'd prefer to not add more static methods. They complicate testing, encourage incorrect layering and have generally not worked out well. |
I have an element that displays different text/links depending on if the user is logged in or not. I'm currently using the "(bool)AuthComponent::user()" syntax that AD suggested, but it seems like code duplication (however small). It's doing the same thing that "loggedIn" does. If the method shouldn't be static because you can use the Auth::user() function, it could be argued that the "loggedIn" function shouldn't be there at all? On a side note: please don't take away my static functions mark <3. If we didn't have any static methods in the AuthComponent, this type of element would have to be accomplished cake1.3 style: code in the app controller and sending vars to the element. However proper that 1.3 style may have been, it seems less elegant. |
Sending vars to the template is much better from an application 'structure' point of view though. It also is inline with the separation of concerns ideas that MVC frameworks desire to promote. While static methods seem elegant, they promote and global variables when the static methods need to refer to state. |
@watermark loggedIn() could probably be deprecated in favor of always using user() itself. Otherwise I agree, it would better be static, too, as its merely a wrapper for user(). |
Closing as the functionality is already fully available with the existing methods? |
+1 deprecate loggedIn(). We should ideally have 1 way to do things, and that way should be the best way. |
Closing as loggedIn() is now deprecated in 2.5. |
Reading this issue, am I right to say that
|
@simkimsia Yes. |
I've run across several instances where having the AuthComponent's "loggedIn" function static would have been useful. It would be a simple change to make the function static.
I think this change is backwards compatible with most code. It may affect people that have called the "loggedIn" function by call_user_func? Perhaps this is a 2.5/3.0 change?
The text was updated successfully, but these errors were encountered: