Objetos
Olá galera, depois de alguns dias de teste... rsrsrs... consegui um modo (não sei se é o melhor) de passar os objetos através das páginas. segue um exemplo que eu fiz:
cliente.php
<?phpclass cliente{ private $id; private $nome; public function __construct($id, $nome){ $this->nome = $nome; $this->id = $id; } public function getNome(){ return $this->nome; } public function getId(){ return $this->id; }}?>index.php
<?phpsession_start();require('cliente.php');$cliente1 = new cliente(01, "Fulano");$cliente2 = new cliente(02, "Ciclano");$cliente3 = new cliente(03, "Beltrano");$cliente4 = new cliente(04, "Zétrano");$clientes = array();$clientes[$cliente1->getId()] = $cliente1;$clientes[$cliente2->getId()] = $cliente2;$clientes[$cliente3->getId()] = $cliente3;$clientes[$cliente4->getId()] = $cliente4;$_SESSION['clientes'] = serialize($clientes);echo "" . $cliente1->getNome() . " <a href=\"editar.php?ID=" . $cliente1->getId() . "\">editar</a><br>";echo "" . $cliente2->getNome() . " <a href=\"editar.php?ID=" . $cliente2->getId() . "\">editar</a><br>";echo "" . $cliente3->getNome() . " <a href=\"editar.php?ID=" . $cliente3->getId() . "\">editar</a><br>";echo "" . $cliente4->getNome() . " <a href=\"editar.php?ID=" . $cliente4->getId() . "\">editar</a><br>";?>editar.php
<?phpsession_start();require('cliente.php');$id = $_GET['ID'];$clientes = unserialize($_SESSION['clientes']);echo $clientes[$id]->getNome();?>
Bom, eu armazeno todos os objetos criados em um ARRAY e armazeno esse ARRAY na SESSION, até aí tudo tranquilo.
Minha pergunta é?
Essa seria a melhor forma de passar esses objetos entre as páginas?
Porque veja bem, eu vou editar apenas um cliente, porque eu jogaria todos eles na SESSION?
Porém não sei como jogar apenas o qual eu quero editar!
Vlwz
Discussão (9)
Carregando comentários...