I need to pass an object to a page. For example: I would like the moment I redirect to a certain page that will display the html, that in it I could retrieve that object and use whatever is in it.
Would anyone have an example of how to do this?
Here's an example I've tried to explain better:
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/exemplomvc/src/model/to/CadastroTO.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/exemplomvc/src/model/cadastro.php';
class CadastroController {
private $cadastroTO;
private $cadastro;
public function __construct() {
$this->cadastroTO = new CadastroTO();
$this->inicializa();
}
/*
*
*/
public function inicializa() {
$codigo = (int) $_POST['codigo'];
$nome = (String) $_POST['nome'];
$this->cadastroTO ->setCodigo($codigo);
$this->cadastroTO ->setNome($nome);
$this->cadastro = new Cadastro($this->cadastroTO);
try {
//variável a ser passada para a pagina.
$dados = $this->cadastro ->consultar();
header("Location: " . $_SERVER['DOCUMENT_ROOT'] . '/exemplomvc/index.php');
}
catch(CadastroException $erro) {
echo $erro ->getMessage();
}
}
}
$obj = new CadastroController();
When this class is called, it will redirect to a page that has the html, and on this page I would like to retrieve this variable "$ data" which contains an instance of the class with gets and sets.
Would it be the best way to start the session variable?