0
I’m making a field to search but 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;
}
progControl
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 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
The last error vc reversed the variables must pass
$objComando
inBusca()
and not$objProg
. Since progControl code is not there there is no way to tell exactly how to resolve but the error message already helps enough ;)– rray
I’ll edit the question he’s there just not signaled. I’ve edited signaling, I don’t know if it helps.
– KevinF