PHP href redirect

0

I have a DAO class that contains all the methods to execute. But when the user enters his access, he does a select from the bank bringing his clients.

Inside the while I put

My question is: how do I call the class DAO and the delete function that contains it?

Example I already did and did not work

echo "<td><a href='UsuarioDAO.php?excluir=$id'><button>Clique</button></td> </a>";

class UsuarioDAO(){

public function excluir(){
//codigo vem aqui
}

}
    
asked by anonymous 13.02.2017 / 16:45

1 answer

2

In the Username.php file, put something like this:

class UsuarioDAO(){

    public function excluir($id){
        //codigo vem aqui
        echo 'ID para excluir: '.$id;
    }

}

/*
Verifica o parâmetro recebido pela URL
*/
$method = 'excluir';
if (isset($_GET[$method])) {
    $id = trim(strip_tags($_GET[$method]));
}

/*
Instancia a classe e invoca o método se existir
*/
$c = new UsuarioDAO;
if (method_exists($c, $method)) {
    $c->{$method}($id);
} else {
    echo 'Método não existe: '.$method;
}
    
13.02.2017 / 17:50