I've been monkeying through the tutorial in the docs:
Code:
https://codeigniter4.github.io/CodeIgniter4/tutorial/index.html
to get my head around this 'new' version.
In this part:
Code:
https://codeigniter4.github.io/CodeIgniter4/tutorial/news_section.html
At the bottom of the paragraph titled "Display the news" I see this:
Code:
<h2><?= esc($news['title']); ?></h2>
<?= esc($news['body']); ?>
Now, this throws and error in my case:
Code:
Undefined index: title
So, in order to correct this I rewrite the above part to this:
Code:
<h2><?= $title; ?></h2>
<? // = esc($news['body']); ?>
If you notice, I commented out the 'body' part as it throws the same error (undefined variable) and I can't seem to see that a 'body' is actually passed into the view anywhere?
What part is it that I completely missed in the process? Remember there is the index method and the view method … defined in the Routes.php. Could it be that somewhere along the tutorial something was missed, or did I just totally screw it all up by myself (yeah, good boy there)?
Yep, and as soon as I posted this ... I found the answer.
I had mistyped
Code:
echo view('templates/header', $data);
echo view('news/view', $data);
echo view('templates/footer', $data);
instead of this:
Code:
echo view('templates/header', $data);
echo view('news/overview', $data);
echo view('templates/footer', $data);
In my index method (note the missing 'over' in overview … ).
Note to self: use copy/paste when following tutorials ...
Rule of life: if you've banged your head against something for a while ... write a post in a forum somewhere (it probably doesn't matter which one) and boom, there's your answer.