Good afternoon guys, I'm starting with php OO and with MVC, I'd like to know if the code snippet runs short of the standards, and if there's any improvement to be implemented. Thanks in advance for your help.
<form method="post" action="getdata.php">
<label>
Nome <input type="text" name="nome" />
</label>
<label>
Email <input type="text" name="email" />
</label>
<input type="submit" value="Enviar" />
</form>
PHP class
<?php
class getData{
private $nome;
private $email;
public function getNome(){
$this->nome = $_POST['nome'];
}
public function getEmail(){
$this->email = $_POST['email'];
}
public function exibir(){
echo $this->nome . ' <br /> ' . $this->email;
}
}
$getData = new getData();
$getData->getNome();
$getData->getEmail();
$getData->exibir();
?>
I'm starting with PHP now but some time I've already programmed with Java, the class name question and the broken encapsulation pillar I realized, this example I found on the net giving a quick researched. I found it strange in a file to create the class and instantiate it in the same file. If it was in java it would do as follows
public class ProcessaDados extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
//recuperaria os dados
String nome = req.getParameter("nome");
String email = req.getParameter("email");
//criaria o Modelo e realizaria o restante da regra
}