I am writing a webapp using CodeIgniter that requires authentication. I created a model which handles all my authentication. However, I can't find a way to access this authentication model from inside another model. Is there a way to access a model from inside another mode, or a better way to handle authentication inside CodeIgniter?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Don't handle authentication in your model. Only use models to interface with your database, or ldap or whatever.
I created an Auth library that I use to manage authentication and authorization. You can access a library like this from your controllers.
It seems you can load models inside models, although you probably should solve this another way. See CodeIgniter forums for a discussion.
Also, I don't understand what Till is saying about that you shouldn't create objects inside objects. Of course you should! Sending objects as arguments looks much less clear to me.
In general, you don't want to create objects inside an object. That's a bad habit, instead, write a clear API and inject a model into your model.
Loading a model within a model is now possible with the new CodeIgniter.