![]() |
Need help with a User class
Recently I'm working on a User class. I need some help with this class to get it on track.
For example, I want a user to get logged in, how would I do this? Do I need to pass the HTML form to the login() function? Or do I need to pass all variables (like email and password) as variables, or?Also, how to correctly interact with the Database class I've written? Should I do something like this? PHP Code:
This is what I have thus far: PHP Code:
|
you just need to pass in the username and password to the login then you do your query to check if its a valid login or not. the login function should return a true or false. The db class can be created like that, that is fine. You will have to store this class in a session variable to keep from reloading it every page as well.
|
Thanks for your reply! It helps me out well.
Quote:
Like: PHP Code:
|
I wouldnt do that.
You need to do things like PHP Code:
Then on the login bit you need to make sessions etc. I will post my one (Please note this wont work properly as it integrates methods etc that my framework has so you will need to change it a lot but you will be able to see what i mean): Please note that its not perfect as i did code it at like 3am. PHP Code:
|
Thanks for your reply too. It's quite hard to read due to no commenting, but I get the trick.
I will soon post my new code. |
Well basically it does:
I then have a isRegistered() function that checks all the information against database et. |
personally I just store the entire user class. Mine is pretty small with only about 8-10 vars and just a couple functions.
A second reason why I save the entire class is so that I don't have to keep doing the same sql queries every time I load the page to get the users name ect. I only run them once when the user logs in. and can then easily access them any time I need. |
I do as well but I just don't want to send him my whole class.
|
Thanks guys. I'm getting more and more into OOP.
At the moment I'm wondering if it's better do do something like this: Create a Login class and a User class. First the user logs in via the Login class. If succesfully logins, the Login class creates a User class with the id of the user f.e. like $pUser = new User(1);. Then the Login class puts the User class in a session.Shouldn't this be more logically (while thinking OOP)? Or am I just lost again? :-p |
That would work, however on one hand does your login class really have much to it? Personally I only have 2 functions and no vars that go with my login. So just adding those 2 to my user class is not much to store. But if you have quiet a few items that are only used in your login then it might make sense to split it up. I don't think it will make a difference one way or the other its really just how you want to do it.
|
No point in 2 classes. Just have a login function
PHP Code:
|
| All times are GMT. The time now is 09:47 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0