Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Dieguinhu Web

Smarty

Recommended Posts

Gente eu tenho um smarty aqui e não to conseguindo editar um registro eu clico no botão e não altera....como eu faço???

 

CODE
<?php

 

require_once(_DIR_WEB_ACTION_."ProjetoAction.php");

require_once(_DIR_WEB_ACTION_."ClienteAction.php");

 

/*Registra funções Xajax*/

$xajax->registerFunction("loadPage");

$xajax->processRequests();

 

 

if( !empty($_GET['id']) || $_GET['area'] == "lista_cliente" ){

/* Lista clientes */

$cliente = new ClienteDAO();

$listaC = $cliente->getCliente($_GET['id'], 20);

 

$projeto = new ProjetoDAO();

$listaN = $projeto->getProjeto($_GET['id'], 2);

 

$smarty->assign("resultP", $listaN);

$smarty->assign("resultC", $listaC);

$smarty->assign("anterior", $cliente->paginacao("anterior", "?area=lista_cliente&load=home"));

$smarty->assign("links", $cliente->paginacao("links", "?area=lista_cliente&load=home"));

$smarty->assign("proximo", $cliente->paginacao("proximo", "?area=lista_clientea&load=home"));

 

/* Fim da lista */

 

}

 

if(empty($_POST['id'])){

$t = new ClienteAction();

$projeto = $t->criaCliente();

 

}else{

$t = new ClienteAction();

$projeto = $t->alteraCliente();

}

 

 

if( $action == "deletar" && !empty($action) && $area == "lista_cliente" ){

$projeto = new ProjetoDAO();

$id = $_GET['id'];

$conditions = " id = " . "'".$id."'";

$projeto->delete("`cc_cliente`", $conditions);

fnAlert("Dados deletados com sucesso!");

fnGoBack(1);

}

Compartilhar este post


Link para o post
Compartilhar em outros sites

É o seguinte no smarty depois de criado um registro existe um botão que linka para um formulario aonde você altera os dados só que em vez de alterar ele na verdade cria um novo registro como posso resolver este rpoblema???

os arquivos q estou utilizando são esses:

home.php

 

CODE
<?php

 

require_once(_DIR_WEB_ACTION_."ProjetoAction.php");

require_once(_DIR_WEB_ACTION_."ClienteAction.php");

 

/*Registra funções Xajax*/

$xajax->registerFunction("loadPage");

$xajax->processRequests();

 

 

 

if( !empty($_GET['id']) || $_GET['area'] == "lista_cliente" ){

/* Lista clientes */

$cliente = new ClienteDAO();

$listaC = $cliente->getCliente($_GET['id'], 20);

 

$projeto = new ProjetoDAO();

$listaN = $projeto->getProjeto($_GET['id'], 2);

 

$smarty->assign("resultP", $listaN);

$smarty->assign("resultC", $listaC);

$smarty->assign("anterior", $cliente->paginacao("anterior", "?area=lista_cliente&load=home"));

$smarty->assign("links", $cliente->paginacao("links", "?area=lista_cliente&load=home"));

$smarty->assign("proximo", $cliente->paginacao("proximo", "?area=lista_clientea&load=home"));

 

/* Fim da lista */

 

}

 

/* Cadastra no BD informações e lista no lista_clientes */

 

if(empty($_POST['id'])){

$t = new ClienteAction();

$projeto = $t->criaCliente();

 

 

}

 

else{

 

header("Location: index.php?area=lista_cliente");

}

 

if( $action == "deletar" && !empty($action) && $area == "lista_cliente" ){

$projeto = new ProjetoDAO();

$id = $_GET['id'];

$conditions = " id = " . "'".$id."'";

$projeto->delete("`cc_cliente`", $conditions);

fnAlert("Dados deletados com sucesso!");

fnGoBack(1);

}

 

 

modifica_cliente.tpl

 

CODE
<script>mostraAba('aba2');</script>

 

<h2>Modificar Cliente</h2>

 

<div id="abasDiv">

<div class="aba1">

<form name="form" method="get" action="" enctype="multipart/form-data">

<input type="hidden" name="MAX_FILE_SIZE" value="999999" />

<!-- Informações Gerais -->

 

<input type="hidden" id="id" name="id" value="{$resultC[0]->id}"/>

<label for="dominio">Nome:</label>

<input type="text" id="nome" name="nome" value="{$resultC[0]->nome}" class="inputText inputTextLargo"/>

 

<label for="servidor">email:</label>

<input type="text" id="email" name="email" value="{$resultC[0]->email}" class="inputText inputTextLargo"/>

 

<label for="login_ftp">Telefone 1 :</label>

<input type="text" id="telefone1" name="telefone1" value="{$resultC[0]->telefone1}" class="inputText inputTextLargo"/>

 

<label for="senha_ftp">telefone2:</label>

<input type="text" id="telefone2" name="telefone2" value="{$resultC[0]->telefone2}" class="inputText inputTextLargo"/>

 

<label for="login_cpanel">Celular:</label>

<input type="text" id="celular" name="celular" value="{$resultC[0]->celular}" class="inputText inputTextLargo"/>

 

<label for="senha_cpanel">Endereco:</label>

<input type="text" id="endereco" name="endereco" value="{$resultC[0]->endereco}" class="inputText inputTextLargo"/>

 

<label for="info_extra">Extra:</label>

<textarea id="info_extra" name="info_extra" class="textAreaMedio">{$resultC[0]->info_extra}</textarea>

 

<p></p>

<input type="submit" value="Modificar notícia" class="inputButton" />

 

</form>

</div>

</div>

 

<!-- fim das abas -->

 

clienteaction.php

CODE
<?php

 

require_once(_DIR_WEB_CLASS_."Paginacao.php");

require_once(_DIR_WEB_DAO_."GenericDAO.php");

require_once(_DIR_WEB_DAO_."ClienteDAO.php");

require_once(_DIR_WEB_VO_."ClienteVO.php");

 

class ClienteAction{

 

/*

*

* @Method: __construct.

* @Parameters: 0.

* @Description: Metodo construtor

* @Return: boolean.

*

*/

function __construct(){

return true;

}

 

 

/*

*

* @Method: criarGaleriaImagem

* @Parameters: 0

* @Description: Gera um objetos. com os dados de uma noticia.

* @Return: array.

*

*/

function criaCliente(){

 

$cliente = new ClienteVO();

$cliente->setId($_POST['id']);

$cliente->setNome($_POST['nome']);

$cliente->setEmail($_POST['email']);

$cliente->setTelefone1($_POST['telefone1']);

$cliente->setTelefone2($_POST['telefone2']);

$cliente->setCelular($_POST['celular']);

$cliente->setEndereco($_POST['endereco']);

$cliente->setInfo_extra($_POST['info_extra']);

$cliente->setImg_cliente(null);

 

$add = new ClienteDAO();

$info = $add->montaCliente($cliente);

$add->adiciona($info);

 

 

return $noticia;

 

}

 

function redirect(){

header("Location: index.php?area=lista_cliente");

}

 

/*

*

* @Method: criarGaleriaImagem

* @Parameters: 0

* @Description: Gera um objetos. com os dados de uma noticia.

* @Return: array.

*

*/

function alteraCliente(){

 

$cliente = new ClienteVO();

$cliente->setId($_POST['id']);

$cliente->setNome($_POST['nome']);

$cliente->setEmail($_POST['email']);

$cliente->setTelefone1($_POST['telefone1']);

$cliente->setTelefone2($_POST['telefone2']);

$cliente->setCelular($_POST['celular']);

$cliente->setEndereco($_POST['endereco']);

$cliente->setInfo_extra($_POST['info_extra']);

$cliente->setImg_cliente(null);

 

$add = new ClienteDAO();

$info = $add->montaClienteID($cliente);

$add->modifica($info,$conditions);

 

 

return $noticia;

 

}

 

}

 

?>

 

projetoDAO.php

 

CODE
<?php

class ProjetoDAO{

 

var $result;

 

/*

*

* @Method: getNoticia

* @Parameters: 1

* @param String id;

* @Description: Busca todas as noticias / se passado o id exibe so 1 noticia.

* @Return: Int.

*

*/

function getProjeto($id = null, $limit = null){

$sql = "SELECT * ";

$sql .= "FROM `cc_login` ";

if(!empty($id)){

$sql .= "WHERE `id` = ? ";

$conditions = array($id);

}

$sql .= " ORDER BY `id` DESC ";

$obj = new CadastroDAO("cc_login");

$resultado = $obj->lista($sql, $conditions, $limit);

$this->result = $obj;

 

return $resultado;

}

 

/*

*

* @Method: getNoticia

* @Parameters: 1

* @param String id;

* @Description: Busca todas as noticias / se passado o id exibe so 1 noticia.

* @Return: Int.

*

*/

function getProjetoCliente($id = null, $limit = null){

$sql = "SELECT * ";

$sql .= "FROM `cc_login` ";

if(!empty($id)){

$sql .= "WHERE `id_cliente` = ? ";

$conditions = array($id);

}

$sql .= " ORDER BY `id` DESC ";

$obj = new CadastroDAO("cc_login");

$resultado = $obj->lista($sql, $conditions, $limit);

$this->result = $obj;

 

return $resultado;

}

 

/**

* modifica categoria na DB

* @param array $info exe. $info = array(nome=>getNome());

* @param String $conditions exe. $conditions = "id = " . $_GET["id"];

* @return boolean

*/

 

function modifica($info, $conditions){

$modifica = new GenericDAO();

$valida = $modifica->modifica($info, $conditions);

return $valida ? true : false ;

}

 

/*

*

* @Method: adiciona

* @Parameters: 1

* @param array $info exe. $info = array(nome=>getNome());

* @Description: Cria o proximo indice para a galeria de Imagem.

* @Return: boolean.

*

*/

function adiciona($info){

 

$cadastra = new GenericDAO();

$cadastra->setTabela('cc_login');

$valida = $cadastra->adiciona($info);

return $valida ? true : false ;

}

 

/**

* Lista categorias.

* @param String $query exe $query = "SELECT * FROM tabela WHERE id = ?";

* @param Array $conditions exe. $conditions = array(1);

* @param String $subarea exe. $subarea = "area=busca";

* @return array de object

*/

function lista($query, $max, $conditions=NULL, $subarea=NULL){

$ini = empty($_GET['pagina']) ? 0 : $_GET['pagina'];

$paginacao = new Paginacao("noticia", $ini, $max, "`id_noticia`", $subarea);

$conteudo = $paginacao->conteudo($query, $conditions);

$this->paginacao = $paginacao;

return $conteudo;

}

 

function paginacao($option, $paging){

$obj = $this->result;

return $obj->links($option, $paging);

}

 

function delete($table, $conditions){

$delete = new GenericDAO("`cc_login`");

$valida = $delete->deleta($table, $conditions);

return $valida ? true : false ;

}

 

function montaProjeto($projeto){

$info = array

(

'`id_cliente`' => $projeto->getIdCliente (),

'`dominio`' => $projeto->getDominio (),

'`servidor`' => $projeto->getServidor (),

'`login_ftp`' => $projeto->getLoginFtp (),

'`senha_ftp`' => $projeto->getSenhaFtp (),

'`login_cpanel`' => $projeto->getLoginCpanel (),

'`senha_cpanel`' => $projeto->getSenhaCpanel (),

'`host_db`' => $projeto->getHostDb (),

'`login_db`' => $projeto->getLoginDb (),

'`senha_db`' => $projeto->getSenhaDb (),

'`info_extra`' => $projeto->getInfoExtra (),

'`img_site`' => $projeto->getImg_site ()

);

 

return $info;

}

 

}

 

 

 

/*

( `id_noticias` , `id_galeria` , `id_video` , `titulo` , `data` , `descricao` , `hyperlink` , `url_imagem` )

 

$noticia = new NoticiaVO();

$noticia->setIdNoticia(null);

$noticia->setIdGaleria($_loc0->id_imagem);

$noticia->setIdVideo($_loc1->id_video);

$noticia->setTitulo($_POST['titulo']);

$noticia->setData($_POST['data']);

$noticia->setDescricao($_POST['descricao']);

$noticia->setUrlImagem($nome);

$noticia->setHyperlink($_POST['hyperlink']);

*/

?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

pela descrição do seu problema suspeito que você esteja utilizando uma mesma página de script para incluir e editar um registro.

você deve verificar se existe um marcador que identifique qual ação está sendo executada e verificar se as condicionais são consistentes.

 

leia o script para entender a lógica.

Compartilhar este post


Link para o post
Compartilhar em outros sites

pela descricao do seu problema, suspeito de duas coisas:

 

1- o script não está recebendo o id referente ao registro.

$_POST['id'];

 

2- o erro pode estar na página tpl, do formulário. verifique se o campo hidden está recebendo o valor

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.