"Catchable fatal error" PHP error

-2

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?

    
asked by anonymous 24.03.2016 / 20:06

2 answers

1

I solved the error by modifying some of the following codes:

View:

<form method="POST" action="../controller/buscaPrecontrole.php">
        <div class="large-12 columns">
            <div class="large-3 columns">
                <input type="date" id="data" name="data" value="" required>
            </div>
            <div class="large-9 columns">
                <input type="submit" class="tiny round button" value="Filtrar"/>
            </div>
        </div>
        <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
                    if(isset($_GET['data'])){

                        $dataPost = $_GET['data'];

                        $objProg = new Prog();
                        $objProg->setdata($dataPost);

                    }else{

                        $dataPost = date('Y-m-d');

                        $objProg = new Prog();
                        $objProg->setdata($dataPost);


                    }


                     foreach ($controller->ListaPorTipoB($objProg) as $objProg) { ?>

Precontrol:

$dataPost = $_POST['data'];

$objProg = new Prog();
$objProg->setdata($dataPost);

$controller = new Comando($conn);
$controller->ListaPorTipoB($objProg);


header ("location: ../view/programacao.php?data=".$dataPost."");
    
29.03.2016 / 14:23
0

I think this works out, because basically the question is that you are calling a method without passing value, in the class it is mandatory to pass a value, to solve you can create a second method that does the same without passing an object, for that there are methods of type Set and Get , however, for the example you are doing it would have to be something similar to this:

<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
                         if(!$_POST) {
                           $content = null;
                           } else {
                             $obj = new Prog();
                             $type = $obj->setdata($_POST['dataa']);
                             if ($controller instanceof Comando)):
                                $content = $controller->ListaPorTipoB($type);
                             }
                        if (!empty($content)):
                           foreach ($content 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 endforeach; ?>
                 <?php else:>
                        <tr>
                          <td colspan="10">Sem registros.</td>
                        </tr>
                 <?php endif; ?>
               <?php else:>
                        <tr>
                          <td colspan="10">Sem registros.</td>
                        </tr>
             <?php endif; ?>
                 </table>
               </div>
         </div>
  </form>

See if instead of doing all this I did above, it would not be better to do this:

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);
//atribuindo a saída para uma variável
$data = $controller->ListaPorTipoB($objProg);

include_once ('../connection_close.php');

In view:

<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 ($data 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>

Just one comment about your class: Be careful with recursive methods as this can affect performance if it is poorly written.

    
24.03.2016 / 21:43