Hi All,
To learn how to use MVC in PHP I followed the tip from many (unfortunaley mostly not very good written) tutorials: make a MVC framework yourself.
I've been trying alot the past day's, grabbed some code from there and there and now I basically got the following structure:
-application
-controllers
defaultController.php
indexController.php
-models
mysql.php
registry.php
router.php
template.php
user.php
-views
header.php
footer.php
index.php
-css
css files
-js
js files
-img
some img files
config.php (mysql conn)
index.php
init.php
phpinfo.php (for phpinfo())
.htaccess
This structure is a combination of the structures of 2 tutorials and my own idea's.
Now I have several questions which I hope you can answer :
- Where is the actual logic code placed, in the model or in the controller? I read alot of contradictory answers in various tutorials.
I'll give an example:
I got a login form on my index. When people submit the form it leads them to the url: www.mysite.com/login
When they go to that url the router loads the indexController.php
But what now? Should indexController call up user.php(the user object) and tell user.php to log the user in and after getting the succes message from user.php it redirects the user to the homepage for people that are logged in.
OR
indexController logs the user in himself using his own method and once the user is succesfully logged in indexController tells user.php that their now is a 'user' and lets user.php make an object from that user.
Or are both these options wrong?
- When I submit for example a login form. Should I always add another var in the url(before submit: mysite.com/shop/, after submit: mysite.com/shop/submit)
so that my router detects 'Hey they submitted a form'. Or is their a way to let the controller itself detect that the form is submitted by POST(so no need for extra get variable)?
Thanks in advance!
Yours Faithfully