It's a little difficult to explain.
Suppose you are creating a CMS. In that CMS you want user to be able to add pages, edit them and delete them. You also want user to be able to add posts, edit them and delete them. You also want user to be able to add, edit, delete products and add, edit, delete categories... (you get the idea.)
Now the way i would handle this problem is i would create separate forms and submit them on the same file that would handle all the process of adding, editing, deleting...
For example: i would create a addpage.php. It'll have a form and it'll submit to a process.php file. The same with posts. addpost.php file and submit to process.php. In these forms I'll also send a hidden input named "p" to identify the process.
For example: on addpage.php the hidden input will be <input type="hidden" name="p" value="addpage">
on addpost.php the hidden input will be <input type="hidden" name="p" value="addpost">
. So in the process.php i will just check the $_POST['p'] using ifelse statements and just perform the task. Some thing like:
if( $_POST['p'] == "addpage" ){
// the process for adding page
}elseif( $_POST['p'] == "editpage" ){
// the process for editing a page
}elseif( $_POST['p'] == "addpost" ){
// the process for adding a post
}
Now this method obviously works fine, but this does not feels like a good programming technique..
How can i handle this in a better way? How can I this OO-ly.
I'm new to OOP and I know most of you will tell me to use a framework. But this is mostly for learning. What is the best possible way of handling this without MVC?