I am following this MVC guide to learn the basics of creating web apps with the MVC pattern.
I have set it all up and it works fine, currently the system works with urls of this form;
address.co.uk/controller/method/params
I understand how this can work, however how would this work when posting data? for example a login form, i have tried accessing the POST variables from the controller, how ever this doesn’t work, im guessing this is due to the .htaccess file sends everything to the index.php?
UPDATE:
so i have created this basic form;
<form name="input" action="register/newuser" method="post">
Username: <input type="text" name="user" />
password: <input type="text" name="pass" />
<input type="submit" value="Submit" />
</form>
That submits data to this controller methods newuser;
function newuser()
{
$data['user'] = $_POST["user"];
$data['pass'] = $_POST["pass"];
$this->loadView('view_register_result',$data);
}
Then finally the result page;
<body>
<h1>Result</h1>
im not sure? <br />
user: <?php echo $data['user']; ?>
pass: <?php echo $data['pass']; ?>
</body>
Is there any reason why this doesn’t work?
$_POSTis a superglobal, meaning that it’s available everywhere. Of course, it won’t be filled unless you do an actual POST.mod_rewritein the .htaccess will only rewrite the URL, but it won’t touch the$_POST,$_SESSIONor$_COOKIE. Only the$_GETmight be changed slightly, but that’s beyond the scope of your question.Edit
Your issue is definitely unrelated to the
$_POST. Does passing$dataas an argument toloadViewadd it to the template as$data, or does it add it as two separate variables: user and pass? In that case, tryloadView('..', array('data' => $data))