-2
I have a field search in which put a dynamic date, posting this date returns me the records of the bank below, but I stuck in this error that happens in foreach
. Follows 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');
Field search and below returns the database 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 Comando::Listaportipob() must be an instance of Prog, None Given, called in C: xampp htdocs view programacao.php on line 76 and defined in C: xampp htdocs controller progControle.php on line 11
I can’t seem to fix this mistake, some hint ?
It’s the same mistake as last question, you need to pass an object
Prog
along those linesforeach ($controller->ListaPorTipoB() as $objProg
– rray
It is mandatory to pass the date to
ListaPorTipoB()
?– rray
No, if there is another way to do it, with the same purpose and is more feasible. And I could not pass the Prog object in this line above.
– KevinF
If the date doesn’t matter, just cut it out 1) of SQL. 2) Remove bind 3) Remove from method
ListaPorTipoB($obj){
in DAO. 4) Remove from honeycombListaPorTipoB(Prog $obj){
in command.– rray
But it does matter. I need it. How do I pass the object to the line you mentioned above ? Because I tried to pass it and it didn’t work, the same error continues.
– KevinF
Before the foreach do
$objProg = new Prog();$objProg->setdata('2016-03-24');
. afterward:foreach ($controller->ListaPorTipoB($objProg) as $objProg
– rray
Only that this date is dynamic as put in the field search on the
foreach
I can’t set it manually there.– KevinF