PHP Orientado a Objeto - MVC
Olá pessoal boa tarde, não sei se a minha dúvida será a dúvida de outras pessoas, venho do mundo da programação estruturada,e como todo processo, estou migrando para orientação a objeto,e está sendo um choque de realidade para mim tentar entender a orientação a objeto, para essanova fase resolvi elaborar um crud simples, que irá cadastrar dados ,alterar,excluir e listar os mesmo, paraisso criei os arquivos deconexãoao banco de dados,o arquiovo de persistencia de dados, e contoledesses dados, o modelo,como get e set e também a visão bem rudimentar apenas para testes, entretanto estou enfrentando problemas paral ligar todos esses arquivos... eu praticamente criei toda a estruturam mas como vou dizer que a visão irá acionar o controle,que irá acionar o modelo,e o modelo vai ligar os dados coletados lá na visão com a classe de persistencia, e adicionar esses dados ao banco de dados.... irei postar a estrutura dos arquivos abaixo,aguardo uma alma gentil a me ajudar.
Estrutura.
/applications/core/interface/imageproxy/imageproxy.php?img=http://uploaddeimagens.com.br/images/000/172/548/full/estrutura.png?1391285898&key=4858682892a6ead49ae70f43af1258f6d95b2532059f5f6dd435d3d5ffb95adf" alt="estrutura.png?1391285898" />
Códigos
_condig->conexao
<?php
/*
* @author: Jerfeson Guerreiro
* @project: sis_astral
* @package admin
*
*/
class conexao
{
private $db_host = 'localhost';
private $db_user = 'root';
private $db_pass = 'root';
private $db_name = 'sis_astral';
private $con = false;
// Função para testar conexão com banco de dados
public function connect(){
if(!$this->con){
$myconn = @mysql_connect($this->db_host, $this->db_user, $this->db_pass, $this->db_name);
if($myconn)
{
$seldb = @mysql_select_db($this->db_name, $myconn);
if($seldb)
{
$this->con = true;
return true;
}
else
{
return false;
}
}else
{
return false;
}
}
else
{
return true;
}
}
public function disconnect(){
if($this->con){
if(@mysql_close()){
$this->con = false;
return true;
}
else {
return false;
}
}
}
}
_config->Crud
<?php
/**
* Created by PhpStorm.
* User: Jerfeson Guerreiro
* Date: 31/01/14
* Time: 21:27
*/
class crud
{
private $sql_ins = "";
private $tabela = "";
private $sql_sel = "";
public function __construct($tabela)
{
$this->tabela = $tabela;
return $this->tabela;
}
public function inserir ($campos,$valores)
{
$this->sql_ins = "INSERT INTO".$this->tabela."(campos) VALUES($valores)";
if(!$this->sql_ins = mysql_query( $this->sql_ins))
{
die ("<center>ERRO NA CONLUSÃO"."<br/>".'LINHA:'.__LINE__."<br />".mysql_error()."<br /><a href='../_visao/index.php' >VOLTAR</a></center>");
}
else
{
print "<script> Location='index.php;'</script>";
}
}
public function alterar($camposvalores, $where = NULL)
{
if($where)
{
$this->sql_upd = "UPDATE".$this->tabela."SET $camposvalores WHERE $where";
}
else
{
$this->sql_upd = "UPDATE".$this->tabela."SET $camposvalores";
}
if(!$this->sql_upd = mysql_query($this->sql_upd)){
dir("<center>ERRO NA ATUALIZAÇÃO"."<br/>Linda>".__LINE__."<br/>".mysql_error()."<br/> <a href='../_visao/index.php'>VOLTAR<a/></center>");
}
else
{
print "<center>tualização efetuada com sucerro <br/> <a href='index.php'>Voltar</a></center>";
}
}
public function excluir($where = NULL)
{
if($where)
{
$this->sql_sel = "SELECT * FROM".$this->tabela. "WHERE $where";
$this->sql_del = "DELECT FROM".$this->tabela. "WHERE $where";
}
else {
$this->sql_sel = "SELECT * FROM".$this->tabela;
$this->sql_del = "DELECT FROM".$this->tabela;
}
$sel = mysql_query($this->sql_sel);
$regs = mysql_num_rows($this->$sel);
if($regs > 0){
if($this->sql_del = mysql_query($this->sql_del)){
die ("<center> ERRO NA EXCLUSÃO"."<br />Linha:".__LINE__."<br />".mysql_error()."<br /><a href='../_visao/index.php'></a>Voltar</center>");
}
else{
print "<center>Escluido com Sucesso<a href='index.php'>Voltar</a></center>";
}
}
else
{
print "<center>Registro não encontrado<a href='index.php'>Voltar</a></center>";
}
}
}
_controle->controle.php
<?php
/**
* Created by Secode.
* User: Jerfeson Guerreiro
* Date: 01/02/14
* Time: 17:44
*/
require('../_modelo/modelo.php');
$p = $_POST;
$cadastro = new cadastro();
$cadastro->setRazaoSocial($p['razaoSocial']);
$cadastro->setNomeFantasia($p['nomeFantasia']);
$cadastro->setCnpj($p['cnpj']);
$cadastro->setDataInscricao($p['dataInscricao']);
$cadastro->setEndereco($p['endereco']);
$cadastro->setCidade($p['cidade']);
$cadastro->setCep($p['cep']);
$cadastro->setBairro($p['bairro']);
$cadastro->setTelefone($p['telefone']);
$cadastro->setCelular($p['celular']);
_modelo->modelo.php
<?php
/**
* Created by Secode.
* User: Jerfeson Guerreiro
* Date: 31/01/14
* Time: 23:35
*/
class cadastro
{
private $razaoSocial;
private $nomeFantasia;
private $cnpj;
private $dataInscricao;
private $endereco;
private $cidade;
private $cep;
private $bairro;
private $telefone;
private $celular;
/**
* @param mixed $bairro
*/
public function setBairro($bairro)
{
$this->bairro = $bairro;
}
/**
* @return mixed
*/
public function getBairro()
{
return $this->bairro;
}
/**
* @param mixed $celular
*/
public function setCelular($celular)
{
$this->celular = $celular;
}
/**
* @return mixed
*/
public function getCelular()
{
return $this->celular;
}
/**
* @param mixed $cep
*/
public function setCep($cep)
{
$this->cep = $cep;
}
/**
* @return mixed
*/
public function getCep()
{
return $this->cep;
}
/**
* @param mixed $cidade
*/
public function setCidade($cidade)
{
$this->cidade = $cidade;
}
/**
* @return mixed
*/
public function getCidade()
{
return $this->cidade;
}
/**
* @param mixed $cnpj
*/
public function setCnpj($cnpj)
{
$this->cnpj = $cnpj;
}
/**
* @return mixed
*/
public function getCnpj()
{
return $this->cnpj;
}
/**
* @param mixed $dataInscricao
*/
public function setDataInscricao($dataInscricao)
{
$this->dataInscricao = $dataInscricao;
}
/**
* @return mixed
*/
public function getDataInscricao()
{
return $this->dataInscricao;
}
/**
* @param mixed $endereco
*/
public function setEndereco($endereco)
{
$this->endereco = $endereco;
}
/**
* @return mixed
*/
public function getEndereco()
{
return $this->endereco;
}
/**
* @param mixed $nomeFantasia
*/
public function setNomeFantasia($nomeFantasia)
{
$this->nomeFantasia = $nomeFantasia;
}
/**
* @return mixed
*/
public function getNomeFantasia()
{
return $this->nomeFantasia;
}
/**
* @param mixed $razaoSocial
*/
public function setRazaoSocial($razaoSocial)
{
$this->razaoSocial = $razaoSocial;
}
/**
* @return mixed
*/
public function getRazaoSocial()
{
return $this->razaoSocial;
}
/**
* @param mixed $telefone
*/
public function setTelefone($telefone)
{
$this->telefone = $telefone;
}
/**
* @return mixed
*/
public function getTelefone()
{
return $this->telefone;
}
}_Visao->index.php
<?php
/**
* Created by Secode.
* User: Jerfeson Guerreiro
* Date: 01/02/14
* Time: 17:59
*/
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
require("../_controle/controle.php");
}
?>
<form action="" method="post">
Razão Social: <input type="text" name="razaoSocial" /><br />
Nome Fantasia: <input type="text" name="nomeFantasia"/><br />
CNPJ: <input type="text" name="cnpj"/><br />
Data de Inscrição: <input type="date" name="dataInscricao"/><br />
Endereço: <input type="text" name="endereco"/><br />
Cidade: <input type="text" name="cidade"/><br />
CEP: <input type="text" name="cep"/><br />
Bairro: <input type="text" name="bairro"/><br />
Telefone: <input type="text" name="telefone"/><br />
<input type="submit" value="Enviar">
</form>Discussão (4)
Carregando comentários...