I have a search field in which put a date dynamically, posting that date returns me the records of the bank below, however I caught in this error that happens in foreach
. Here is the code:
DAO:
public function ListaPorTipoB($obj){
$results = array();
$stmt = $this->conn->prepare('SELECT * FROM GTCLogist WHERE DsTpVeiculo = \'Bitruck\' AND DtBase = ?');
$stmt->bindValue(1, $obj->getdata());
if($stmt) {
while($row = $stmt->fetch(PDO::FETCH_OBJ)) {
$prog = new Prog();
$prog->setid($row->ID);
$prog->setst($row->DsStatus);
$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;
}
Controller:
class Comando{
private $conn;
public function __construct($connec) {
$this->conn = $connec;
}
public function ListaPorTipoB(Prog $obj){
$dao = new ProgDAO($this->conn);
return $dao -> ListaPorTipoB($obj);
}
}
Precontrol:
include_once ('../connection_open.php');
include_once ('../model/prog.php');
include_once ('progControle.php');
include_once ('../DAO/progDAO.php');
$dataPost = $_POST['dataa'];
$objProg = new Prog();
$objProg->setdata($dataPost);
$controller = new Comando($conn);
$controller->ListaPorTipoB($objProg);
header ("location: ../view/programacao.php");
include_once ('../connection_close.php');
Search field and below returns the bank records:
<form method="POST" action="../controller/buscaPrecontrole.php">
<div class="large-12 columns">
<div class="large-3 columns">
<input type="date" id="dataa" name="dataa" value="" required>
</div>
<div class="large-9 columns">
<input type="submit" class="tiny round button" value="Filtrar"/>
</div>
</div>
<br><br><br>
<div class="large-12 columns">
<div class="TableCSS">
<table>
<tr>
<td>ST</td>
<td>BITRUCK</td>
<td>Motorista</td>
<td>Data Saída</td>
<td>Origem</td>
<td>Destino</td>
<td>Previsão chegada</td>
<td>Carga/Manifesto</td>
<td>Adiantamento Fincanceiro</td>
<td>Agendas</td>
<td>Malotes</td>
<td colspan="2">Observação</td>
</tr>
<?php foreach ($controller->ListaPorTipoB() as $objProg) { ?>
<tr>
<td><?php echo $objProg->getplaca(); ?></td>
<td><?php echo $objProg->getmot(); ?></td>
<td><?php echo $objProg->getsaida(); ?></td>
<td><?php echo $objProg->getorig(); ?></td>
<td><?php echo $objProg->getdest(); ?></td>
<td><?php echo $objProg->getprev(); ?></td>
<td><?php echo $objProg->getcarga(); ?></td>
<td><?php echo $objProg->getadfin(); ?></td>
<td><?php echo $objProg->getagen(); ?></td>
<td><?php echo $objProg->getmal(); ?></td>
</tr>
<?php } ?>
</table>
</div>
</div>
</form>
Catchable fatal error : Argument 1 passed to Command :: ListBypeB () must be an instance of Prog, none given, called in C: \ xampp \ htdocs \ view \ program.php on line 76 and defined in C: \ xampp \ htdocs \ controller \ progControle.php on line 11
I can not solve this error, any tips?