Hi, I have an User management (by Ektanjali) plugin, and it is working, but, after I do the User Auth, I need to load an another plugin interface, and I don’t know how to do that, because the layout of the Users plugin is inside the layout of the AdminLTE plugin, but I dont want that. How can I solve that? If you don’t understand, reply asking me, please, I really need to solve that.
The other plugin should be loaded only for people who are logged in? When you say “plugin”, do you mean that in the CakePHP sense (i.e. these are both CakePHP plugins), or a more general sense?
It feels like you are just going to do something like:
if ($this->isAuthorized()) { //or whatever your plugin check is
$this->loadPlugin('AdminLTE'); //or whatever your correct load command is
}
Those two plugins seem to be for different Cake versions. What version are you in and where are you currently loading the plugins? Show your current code?
That error message is simply telling you that the propery UserAuth does not exist on Application.php. You’re trying to use UserAuth as though you expect it to be an object…
What are you expecting it to be? Where do you believe it is being set? Possibly you have a typo? Or maybe you are expecting a tool to magically appear for your use ?
I’ve recently had a bit of a struggle like this, though not auth related, so my solution won’t be useful to you. The problem is that plugins get loaded early in the process, but authentication isn’t done (especially if you’re expecting “remember me” cookies to kick in and affect this) until the middleware stack is executing. I’d love to hear about any robust and Cake-standard way to handle this!
I understand the error, but I can’t understand how to call this propery $UserAuth to application.php, because this function exists in the UserAuthComponent.php of the users plugin and I’d already used this propery in another file to give layout permissions and it worked, so I don’t understand why it isn’t working there.
I’m going to look if I see where this propery is being set, if I find, I’ll problably come back here with more doubts hhahaah
At the time that bootstrap.php and Application.php are running, authentication doesn’t exist yet. If you’re using the authentication plugin, it’s added as part of the middleware stack; if you’re using the authentication component, it’s initialized when the controller is. Both of these happen after where you’re trying to reference it.
It looks like $UserAuth is a component. This will be available in Controllers. But Application.php is outside that scope.
AdminLTE looks like it has both Model and Helper tools.
So you could possibly run your conditional plugin loading in AppController initialize or somewhere early like that. Your Component should be available and ready to go in that context.
hmm… yes. looks like plugin installs is only supported in Application.php with addPlugin(). I was distracted by the fact that the AdminLTE plugin appears to only using a Behavior and Helper, two classes that can be loaded anytime before needed.
So the question is, in Application.php context, what tools does your auth provided to make the decision.
I see you tool is based on the Cake Authentication component. Probably the Session indicates whether the user is logged in. I guess in the absence of UserAuth you could use the Session to look and see if there is a logged in user.
But what the heck are they making available for you?
You could debug Application.php and/or the Request to see what is in them (and what the property is named). Looking in mine on cake 4.x I see the event manager. It might be possible to register an event in Application.php that will load the plugin, then in AppController trigger the event.
This is an interesting idea. I may give this a try in my project and see whether it works.
For the OP, can you not just always enable the plugin, but then later on only set the theme to it and load its form helper if it’s an admin that’s logged in?