![]() |
OOP - Question[s]
Introduction: [Not Important]
Well I am pretty new to PHP programming and have been doing it for about 2 months on and off but I finally broke down and had to ask a few questions that have been stumping me with my code... Question: First off I am playing with OOP and MVC pattern and I am just basically experimenting with it and trying to learn how things work. Now Ive run into a question, my problem is I have a log in form here... HTML Code:
<form name="login" method="post" action="">HTML Code:
<form name="login" method="post" action="">PHP Code:
So again the question is how do I get the form to post to the controller(or wherever it should go) so I can then execute the rest of the log in process. If my question Isn't clear I will try and explain more clearly or if you need more code examples or details just let me know. Thanks so much :-D |
You can send it anywhere you want, basically.
Two options leap to mind; Send it to itself. Include some kind of procedural code in the head of your login page that looks something like: PHP Code:
OOP is like driving in the city, there's about 30 ways to get anywhere. You could additionally contain the view inside the class, and just instantiate a new object on page load which would then determine if it needs to process the form, display the form, or redirect based on criteria you put into it's constructor. -m |
Thanks a lot for the help and as I said I am new to this so correct me where I am wrong or let me know if I am missing the point.
I understand the first bit of code. PHP Code:
The second method "intermediary controller" sounds like the MVC style. How would you go about doing that? Cause I tried sending my form data to the user_controller.php HTML Code:
<form name="login" method="post" action="<?php echo dirname(__FILE__) . "/user_controller.php"; ?>"> |
Well, one way would be to transfer the logic to your user_controller.php file, something like this:
PHP Code:
If you're not yet familiar with them, you can read up on them at the PHP site. -m |
Well thanks so much delayedinsanity for your help, I figured out why it was not working in the first place, I had the log in form pointing to the wrong file... so when I changed it to the correct one it executed perfectly. Once again thanks.
Also I do have another question about my front controller. It works perfectly when I point it to a file I have made, and it also works when a page cannot be found but I cant figure out how to make it have a default page to display for my index. Example: If I go to a page that exists like http://localhost/rome/index.php?page=user&action=login Then it loads it up perfectly. And when I go to a page that doesn't exist like http://localhost/rome/index.php?page=free&action=money it displays the 404 error page like it should... So the question is when I want it to point to the main index file http://localhost/rome/index.php How do I get it to load up a default home page when someone goes to the index.php? Because all I get from it is my 404 error page. index.php PHP Code:
PHP Code:
PHP Code:
PHP Code:
|
| All times are GMT. The time now is 02:10 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0