Skip to content
Advertisement

CodeIgniter 4 – How to display Flashdata inside a View?

I’m upgrading my project from CodeIgniter 3 to CodeIgniter 4, I’m trying to display a flashdata message inside a view but unfortunately I get differents error for each method I try.

In CodeIgniter 3, I used to call something like:

JavaScript

I try the same in CodeIgniter 4 but I get this error:

JavaScript

Can any one show me how to achieve this ? Thanks in advance.

Advertisement

Answer

I just use another way to display a flashdata and it works fine.

In my controller, I added a new index to the data passed to the view:

JavaScript

Then in the view login.php I call it like this:

JavaScript

UPDATE:

I just use the markAsFlashdata() method and It works perfectly. Here’s what I did in the controller just before the return method:

JavaScript

Then in the view I access the flashdata using $_SESSION['error']:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement