I'm doing a search field but it returns me some errors. My code:
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>
Problems:
Warning : Missing argument 1 for Command :: __ 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 Command :: Search () must be an instance of Command, 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