How to access data coming from the form in object orientation

0

How do I get information coming from POST of the form, so that this data enters a decision structure, Example: I have an abstract class with the function of entering the system, however in the form the user has to check if it is employee, or deliverer, the class that inherits the method to enter first needs to know whether this login is the employee of the company or the deliverer, as both will be directed to different screens.

PAGINA INDEX, NÃO COLOQUEI O FORMULARIO PARA NÃO FICAR EXTENSO DEMAIS.

require_once 'Log.php';

$ logando = new Login ($ user, $ password); $ logando -> setUsuario ($ _ POST ['user']); $ logando-> setSenha ($ _ POST ['password']);

LOGIN PAGE:

public function __construct($usuario, $senha) {
    $this->usuario = $usuario;
    $this->senha = $senha;

}

function getUsuario() {
    return $this->usuario;
}

function getSenha() {
    return $this->senha;
}

function setUsuario($usuario) {
    $this->usuario = $usuario;
}

function setSenha($senha) {
    $this->senha = $senha;
}


abstract public function Entrar($usuario, $senha);
abstract public function Sair();     
abstract public function Erro();

}

HOME PAGE

class Logar extends Login {

private $con;

public function __construct($usuario, $senha) {
    parent::__construct($usuario, $senha);
    $this->con = new Conexao();
}


public function Entrar($usuario, $senha) {
    parent::Entrar($usuario, $senha);
    echo "Método entrar esta funcionando";
}

public function Sair(){
    echo "Saindo";
}

public function Erro() {
    echo "Erro";
}

}

    
asked by anonymous 07.12.2017 / 18:41

1 answer

1

Try to leave your method like this:

public function Entrar() 
{
    echo $this->getUsuario() . ' - ' . $this->getSenha(); // Imprime usuário e senha recebidos p/ testar
}

On the object, in the scope where your code is running, you call the Entrar() method if the condition is true:

if (isset($_POST['botao']) && $_POST['botao'] == 'Login Funcionário')
{
    $obj = new Logar(); // Instancia o objeto da classe Logar

    $obj->setUsuario($_POST['usuario']); // Atribui usuário
    $obj->setSenha($_POST['senha']); // Atribui senha
    $obj->Entrar(); // Chama o método Entrar()
}

Do not forget to treat data coming from $_POST .

EDIT:

$usuario and $senha are data coming from $_POST ? Are you assigning these values to these variables before?

If yes, then if you are passing $usuario and $senha to the constructor method, then it is not necessary to pass again by calling: $logando->setUsuario($_POST['usuario']); and $logando->setSenha($_POST['senha']); , because there you call __construct() of class and assigns the values to the properties.

Another thing I found is in your method Entrar() of the child-class (Logar). In it you are calling the Entrar() method of the parent class that is abstract through parent::Entrar($usuario, $senha); , that is, it has no implemented functionality.

    
07.12.2017 / 23:32