Fórum URL amigável adicionando vários links a barra de navegação #544909
06/02/2016
0
<!doctype html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<title>URL amigavel</title>
</head>
<body>
<?php
$usuario = new Usuario();
if(isset($_POST['cad'])){
$nome = (trim($_POST['nome']));
$email = (trim($_POST['email']));
$usuario->setNome($nome);
$usuario->setEmail($email);
if($usuario->insert()){
echo "<b>Usuario cadastrado com sucesso.</b>";
}
}
?>
<?php
if(isset($_POST['edit'])){
$id = $_POST['id'];
$nome = (trim($_POST['nome']));
$email = (trim($_POST['email']));
$usuario->setNome($nome);
$usuario->setEmail($email);
$usuario->update($id);
}
?>
<?php
if(isset($param[1]) && $param[1] == 'del'){
$id = (int)$param[2];
$usuario->delete($id);
}
?>
<?php
if(isset($param[1]) && $param[1] == 'edit'){
$id = (int)$param[2];
$resultado = $usuario->find($id);
?>
<form action="" method="post">
<label for="nome">Nome:</label><br>
<input type="text" id="nome" name="nome" value="<?php echo $resultado->nome;?>"><br><br>
<label for="email">E-mail:</label><br>
<input type="text" id="email" name="email" value="<?php echo $resultado->email;?>"><br><br>
<input type="hidden" name="id" value="<?php echo $resultado->id;?>">
<input type="submit" value="Atualizar" name="edit">
</form><br>
<?php }else{?>
<form action="" method="post">
<label for="nome">Nome:</label><br>
<input type="text" id="nome" name="nome"><br><br>
<label for="email">E-mail:</label><br>
<input type="text" id="email" name="email"><br><br>
<input type="submit" value="Cadastrar" name="cad">
</form><br>
<?php }?>
<table border="1" bordercolor="#999">
<tr>
<td>#</td>
<td>Nome</td>
<td>Email</td>
<td>Acoes</td>
</tr>
<?php foreach($usuario->findAll() as $l):?>
<tr>
<td><?php echo $l->id;?></td>
<td><?php echo $l->nome;?></td>
<td><?php echo $l->email;?></td>
<td>
<?php echo "<a href='cadastro/edit/".$l->id."'>Editar</a>";?>
<?php echo "<a href='cadastro/del/".$l->id."' onclick='return confirm(\"Deseja realmente deletar?\")'>Deletar</a>";?>
</td>
</tr>
<?php endforeach;?>
</table>
</body>
</html>
Wesley Jonas
Curtir tópico
+ 0Posts
06/02/2016
Marcio Araujo
[url]http://blog.thiagobelem.net/aprendendo-urls-amigaveis[/url]
Gostei + 0
07/02/2016
Marcio Araujo
Gostei + 0
08/02/2016
Wesley Jonas
Gostei + 0
08/02/2016
Marcio Araujo
<?php echo "<a href='cadastro/edit/".$l->id."'>Editar</a>";?>
Achei esse outro:
[url]http://wbruno.com.br/php/desmistificando-urls-amigaveis-com-php-e-htaccessapache/[/url]
Gostei + 0
08/02/2016
Wesley Jonas
Gostei + 0
09/02/2016
Wesley Jonas
Olhe na imagem como fica minha url.
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)