Form handling OOP PHP
I have a question about form handling with OO programming,
The way I am doing it now is:
-> html form (action=action.php?a=login)
the action.php file:
switch ( $_GET['a'] ) {
case 'login':
login stuff;
break;
}
but I don't like it this way( it looks ugly, and i开发者_如何学JAVAts far from OOP ) and I think theres a better way, I dont know how.
I want to ask how can I do this on a good way. Btw I use MVC
You'd either have to come up with a MVC framework stack that uses OOP yourself, or use one of the many frameworks out there. The usual method is to map actions to controller methods.
So /users/login
would look like
class UsersController {
function login() {
//do your login stuff here
}
}
As an initial step, you could move your actions to separate files and start grouping them by how they are related rather than having all your methods inside actions.php
.
精彩评论