CodeIgniter Forums
Tutorial in docs has errors, or? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Tutorial in docs has errors, or? (/showthread.php?tid=77464)



Tutorial in docs has errors, or? - blaasvaer - 09-04-2020

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.


RE: Tutorial in docs has errors, or? - captain-sensible - 09-04-2020

well i'm a Slackware Linux user i.e a Slacker and even i don't like that coding lazyness for goodness sake you save a couple of chars with abomination abbreviation. Best thing is pretend you ddon't see it.

As for the rest of the documentation, I read it, implemented it and my web is working . So the moral of the story is ..