Error Exception Codeigniter4 Invalid argument

48 Views Asked by At

When I try to display the crud, it gives me an error in the foreach. I don't understand the error because I haven't been studying php for long. I code on Codeigniter4 and here is my code:

       <?php
        foreach($membres_detail as $row){      
        ?>
        <tr id="<?php echo $row->id; ?>">
            <td><?php echo $row->id; ?></td>
            <td><?php echo $row->pseudo; ?></td>
            <td><?php echo $row->email; ?></td>
            <td>
            <a data-id="<?php echo $row->id; ?>" class="btn btn-primary btnEdit">Modifier</a>
            <a data-id="<?php echo $row->id; ?>" class="btn btn-danger btnDelete">Supprimer</a>
            </td>
        </tr>
        <?php
        }
        ?>

My Controller :

    public function index()
    {    
        $model = new MemberModel();
   
        $data['membres_detail'] = $model->orderBy('id', 'DESC')->findAll();
          
        return view('list', $data);
    }    

My Model :

class MemberModel extends Model
{
    protected $table      = 'membres';
    protected $primaryKey = 'id';

    protected $useAutoIncrement = true;

    protected $returnType     = Entities\MemberEntity::class;

    protected $allowedFields = ['email','pseudo','password','id_role','status'];

The Error:

ErrorException
Undefined variable $membres_detail

APPATH\Views\list.php at line 35

<?php
foreach($membres_detail as $row)
?>
0

There are 0 best solutions below