Estou fazendo um campo para busca porém me retorna alguns erros. Meu código:
class Prog{
private $DtBase;
public function setdata($DtBase){
$this->data = $DtBase;
}
public function getdata(){
return convertarData($this->data);
}
public function convertarData($data)
{
$exp = explode("/",$data);
return $exp[2].'-'.$exp[1].'-'.$exp[0].'-';
}
}
progDAO
class ProgDAO{
private $conn;
public function __construct($connection){
$this->conn = $connection;
}
public function Busca($obj){
$results = array();
$stmt = $this->conn->prepare('SELECT * FROM GTCLogist WHERE DtBase = "'.$obj->getdata().'" ');
$stmt->execute();
if($stmt) {
while($row = $stmt->fetch(PDO::FETCH_OBJ)) {
$prog = new Prog();
$prog->setid($row->ID);
$prog->setst($row->DsStatus);
$prog->setcarreta($row->CdCarreta);
$prog->setplaca($row->NrPlaca);
$prog->setmot(stripslashes($row->DsMotorista));
$prog->setsaida(date('d/m/Y', strtotime($row->DtSaida)));
$prog->setorig($row->DsOrigem);
$prog->setdest($row->DsDestino);
$prog->setprev(date('d/m/Y', strtotime($row->DtPrevChegDest)));
$prog->setcarga($row->DsCarga);
$prog->setadfin($row->DsAdFin);
$prog->setagen($row->DsAgendas);
$prog->setmal($row->DsMalote);
$prog->setobs($row->DsObservacao);
$results[] = $prog;
}
}
return $results;
}
progControle
class Comando{
private $conn;
public function __construct($connec) {
$this->conn = $connec;
}
public function Busca(Comando $obj){
$dao = new ProgDAO($this->conn);
return $dao -> Busca($obj);
}
}
progPrecontrole
include_once ('../connection_open.php');
include_once ('../model/prog.php');
include_once ('progControle.php');
include_once ('../DAO/progDAO.php');
$dataPost = $_POST['data'];
$objProg = new Prog();
$objProg->setdata($dataPost);
$objComando = new Comando();
$objComando->Busca($objProg);
header ("location: ../view/busca.php");
include_once ('../connection_close.php');
<html>
<head>
<title>Busca</title>
</head>
<body>
<h1 align="center">Campo para busca</h1>
<form action="../controller/progPrecontrole.php" method="POST" onsubmit="return valid();">
Data: <input type="date" id="data" name="data">
<input type="submit" class="success round button" value="Buscar"/>
</form>
</body>
</html>
Problemas:
Warning: Missing argument 1 for Comando::__construct(), called in C:\xampp\htdocs\Teste2\controller\progPrecontrole.php on line 16 and defined in C:\xampp\htdocs\Teste2\controller\progControle.php on line 7
Notice: Undefined variable: connec in C:\xampp\htdocs\Teste2\controller\progControle.php on line 8
Catchable fatal error: Argument 1 passed to Comando::Busca() must be an instance of Comando, instance of Prog given, called in C:\xampp\htdocs\Teste2\controller\progPrecontrole.php on line 17 and defined in C:\xampp\htdocs\Teste2\controller\progControle.php on line 11
$objComando
emBusca()
e não$objProg
. Como o códigode progControle não está ai não tem como dizer exatamente como resolver mas a mensagem de erro já ajuda bastante ;)