I am following a mvc tutorial but i dont understand how and why my code does't work.
So i have a Controller like so.
public function indexAction()
{
$formSent = false;
if (isset($_POST['send'])){
$formSent = true;
}
$this->view->setVars([
'name' => 'Stefan',
'formSent' => $formSent
]);
}
and my form which is located in views/index
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Forumlar</title>
</head>
<body>
<form method="post" action="/index">
<table>
<tr>
<td>Vorname</td>
<td><input type="text" name="vorname"></td>
</tr>
<tr>
<td>Nachname</td>
<td><input type="text" name="nachname"></td>
</tr>
<tr>
<td>PLZ</td>
<td><input type="number" name="plz"></td>
</tr>
</table>
<button type="submit" name="send">Send</button>
</form>
</body>
<?php
echo $name;
if ($formSent){
echo "Form is Sent!";
}
?>
To make my question more simple to understand and where my problem is.
So echoing $name, does output in this case "Stefan". While anything that is done with the form doesn not work.
For example dumping _POST will be empty and my if formSent statement does not work.
So how exacltey do i "connect" these two or how does it work ?
Thank you.
EDIT: Here its waht it says after i send the form
Object not found! The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
If you think this is a server error, please contact the webmaster.
Error 404
EDIT 2:
Yes i do thave this in my IndexController
protected $view;
public function setView(\Mvc\Library\View $view)
{
$this->view = $view;
}
To connect the view to controller, u need to load the view page in controller..
in controller,
public function index() {
$this->load->view('YOUR PAGE NAME IN VIEW FOLDER');
}