Fatal error: Can not use object of type Course as array in

0

Hello, I have this function that pulls out an array but when I try to get the name of the following form, for example [0] ['name'] tells me that the object of type Course can not be used as a matrix.

public function mostrarCurso(){
    $db = BaseDatos::conectar();
    $listadoCurso = [];

    $select = $db->query('SELECT * FROM Curso');
    /*Si no están los setters no se mostrarán en la tabla*/
    foreach ($select->fetchAll() as $curso) {
    // foreach ($select->fetch(PDO::FETCH_ASSOC) as $curso) {
        $myCurso = new Curso();
        $myCurso->setIdCurso($curso['id_curso']);
        $myCurso->setNombreCurso($curso['nombre']);
        $myCurso->setCantAlumnos($curso['cant_alumnos']);
        $myCurso->setFechaInicio($curso['fecha_inicio']);
        $myCurso->setFechaFin($curso['fecha_fin']);
        $myCurso->setNivelCurso($curso['nivel_curso']);
        $myCurso->setFoto($curso['foto']);
        $myCurso->setEstadoCurso($curso['estado']);
        $listadoCurso[] = $myCurso;
    }
    return $listadoCurso;
}
    
asked by sergibarca 11.04.2018 в 13:56
source

1 answer

0

The problem was that what was happening were objects, what I do is json_decode (json_decode ()) to generate an Array.

$curso = json_decode(json_encode($crudCurso->mostrar()), true);

And in this way I will be able to recover the data in the following way,

$curso['nameCurso'];
    
answered by 11.04.2018 / 16:08
source