-2
I was making some changes in my code, changes that were the visibility of class attributes (I changed the attributes from public to private and am using getters and setters methods)
Only that the following error is occurring in the Tabela de listagem
.
Fatal error: Uncaught Error: Call to a member function getAluno() on array
- Class
Aluno
abstract class Aluno extends BD {
protected $tabela;
private $cd_aluno, $nome, $endereco;
public function getAluno() {
return $this->cd_aluno;
}
public function getNome() {
return $this->nome;
}
public function getEndereco() {
return $this->endereco;
}
public function setAluno($cd_aluno) {
$this->cd_aluno = $cd_aluno;
}
public function setNome($nome) {
$this->nome = $nome;
}
public function setEndereco($endereco) {
$this->endereco = $endereco;
}
}
- Class
CrudAluno
class CrudAluno extends Aluno{
protected $tabela = 'aluno';
public function Select() {
$sql = "SELECT * FROM $this->tabela";
$stm = BD::prepare($sql);
$stm->execute();
return $stm->fetchAll(PDO::FETCH_ASSOC);
}
}
- Listing table
<table id="lista" border="1">
<tr>
<th> ID </th>
<th> Nome </th>
<th> Endereço </th>
<th> Ações </th>
</tr>
<?php
foreach ($aluno->Select() as $key){
echo '<tr>';
echo '<td>'.$key->getAluno().'</td>';
echo '<td>'.$key->getNome().'</td>';
echo '<td>'.$key->getEndereco().'</td>';
echo '<td>'."<a href='/crud/formulario/form_atualizar.php/#atualizar'>Atualizar</a> ".
"<a href='/crud/formulario/form_excluir.php/#excluir'>Excluir</a>".'</td>';
echo '</tr>'; echo '</p>';
}
?>
</table>
$aluno->Select()
returns aarray
ofarrays
. https://www.php.net/manual/en/pdostatement.fetchall.php– Augusto Vasques