This is my first attempt to write something using OOP, I usually use code like spagethi with a lot of functions, but I want to try and improve my PHP skills, so I'm currently learning and consider myself a newbie / newbie, you can see in my code. Keep this in mind when answering / reading.
So, I created a controller with my classes and methods.
Then I have a view, which is a simple registration form.
A model called router.php works as follows. The user submits the form in which he receives the page from which the form was submitted, and explode () it. if the page name matches the page name hardcoded inside the router function, it will process the php code received from the controller.
The problem with this is that the page name is hardcoded in the router model $page = explode('/', $URL) if($page[3] == 'signup.php'){}, if the page name changes, this will lead to an error. How can I improve this?
model /router.php
$URL = $_POST['url'];
$page = explode('/', $URL);
if($page[3] == 'signup.php'){
require_once('../controller/users.php');
$obj = new employer();
$obj->setEmployerName($_POST['fullname']);
$obj->getEmployerFirstname();
$obj->getEmployerLastName();
$obj->setPword($_POST['pword']);
$obj->setEmail($_POST['email']);
echo $obj->registerNewEmployer();
?>
VIEW REGISTRATION
<form role="form" id="registerForm" name="registerForm" method="post" action="../model/router.php">
<div class="form-group">
<label for="fullname" class="col-2 col-form-label">Fullname</label>
<div class="col-4">
<input type="text" name="fullname" required="required" id="fullname" class="form-control" placeholder="Enter Fullname" />
</div>
</div>
<div class="form-group">
<label for="email" class="col-2 col-form-label">Email</label>
<div class="col-4">
<input type="email" name="email" required id="email" class="form-control" placeholder="Enter Email Address" />
</div>
</div>
<div class="form-group">
<label for="pword" class="col-2 col-form-label">Password</label>
<div class="col-4">
<input type="password" name="pword" required="required" id="pword" class="form-control" placeholder="Enter Password" />
</div>
</div>
<div class="form-group">
<label for="pword2" class="col-2 col-form-label">Confirm Password</label>
<div class="col-4">
<input type="password" required id="pword2" name="pword2" class="form-control" placeholder="Confirm Password" />
</div>
</div>
<div class="form-group">
<input type="text" style="display: none" name="url" value="<?php echo $_SERVER['REQUEST_URI'] ?>" />
<button class="btn btn-info btn-size form-control" name="submitBtn" id="submitBtn">Join</button>
</div>
</form>
Question
As mentioned above ... The problem with the "router.php" script is that the page name is hardcoded in the router model $page = explode('/', $URL) if($page[3] == 'signup.php'){}if changing the page name results in an error. How can I improve / change this?