Robbert Stevens
Robbert Stevens

Reputation: 336

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 its 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

Upvotes: 1

Views: 963

Answers (1)

JohnP
JohnP

Reputation: 50019

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.

Upvotes: 4

Related Questions