I'm trying to learn more about MVC in PHP. But I have encountered a problem: I want to show my view in a specific place within a specific div. How can I do this? This is what I have right now:
Controller :
class LogarController extends Controller {
private $view;
private $modelDAO;
function __construct() {
parent::__construct();
$this->modelDAO = new LogarModel();
$this->view = new LogarView();
}
/**
* metodo Login().
* funcao para logar o funcionario ja cadastrado ao banco de dados.
*/
public function Login() {
if ($this->modelDAO->Login($_POST['funcionario'], $_POST['senha'])) {
$idFuncionario = $this->modelDAO->rows['idFuncionario'];
$this->sessao = new Session();
$this->sessao->set_value("logado",true);
$this->sessao->set_value("idFuncionario",$idFuncionario);
$this->redirect("view/funcionario/index.php");
} else {
$this->view->show("Funcionario not found");
}
}
}
View:
class view {
function __construct(){}
function __set($var,$value){
$this->var = $value;
}
function __get($var){
return $this->var;
}
function render($render){
require "view/template/" . $render . ".php";
}
function show($value){
$this->value = $value;
}
function alertar($value){
echo "<script>alert('{$value}')</script>";
}
}
I want to show "Funcionario not found" under the button. How can I do this? Do I need to redirect the page?
P.S.: I'm not using any framework.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…