diff --git a/user_guide_src/source/tutorial/news_section.rst b/user_guide_src/source/tutorial/news_section.rst index 40e8d3ad6da8..81badbd79c5a 100644 --- a/user_guide_src/source/tutorial/news_section.rst +++ b/user_guide_src/source/tutorial/news_section.rst @@ -98,7 +98,7 @@ some additional tools to make working with data simpler. Add the following code to your model. .. literalinclude:: news_section/002.php - :lines: 11-18 + :lines: 11-23 With this code, you can perform two different queries. You can get all news records, or get a news item by its slug. You might have diff --git a/user_guide_src/source/tutorial/news_section/002.php b/user_guide_src/source/tutorial/news_section/002.php index 5d4b11f7cd62..3a17f4285ad0 100644 --- a/user_guide_src/source/tutorial/news_section/002.php +++ b/user_guide_src/source/tutorial/news_section/002.php @@ -8,6 +8,11 @@ class NewsModel extends Model { protected $table = 'news'; + /** + * @param false|string $slug + * + * @return array|null + */ public function getNews($slug = false) { if ($slug === false) { diff --git a/user_guide_src/source/tutorial/news_section/003.php b/user_guide_src/source/tutorial/news_section/003.php index 22b24577b01e..fe5c0378bfa4 100644 --- a/user_guide_src/source/tutorial/news_section/003.php +++ b/user_guide_src/source/tutorial/news_section/003.php @@ -10,10 +10,10 @@ public function index() { $model = model(NewsModel::class); - $data['news'] = $model->getNews(); + $data['news_list'] = $model->getNews(); } - public function show($slug = null) + public function show(?string $slug = null) { $model = model(NewsModel::class); diff --git a/user_guide_src/source/tutorial/news_section/004.php b/user_guide_src/source/tutorial/news_section/004.php index 625acaf805cf..1f17215e0294 100644 --- a/user_guide_src/source/tutorial/news_section/004.php +++ b/user_guide_src/source/tutorial/news_section/004.php @@ -11,8 +11,8 @@ public function index() $model = model(NewsModel::class); $data = [ - 'news' => $model->getNews(), - 'title' => 'News archive', + 'news_list' => $model->getNews(), + 'title' => 'News archive', ]; return view('templates/header', $data) diff --git a/user_guide_src/source/tutorial/news_section/005.php b/user_guide_src/source/tutorial/news_section/005.php index 39db0a4319f7..0fdfd46e8101 100644 --- a/user_guide_src/source/tutorial/news_section/005.php +++ b/user_guide_src/source/tutorial/news_section/005.php @@ -1,8 +1,8 @@

- + - +

diff --git a/user_guide_src/source/tutorial/news_section/006.php b/user_guide_src/source/tutorial/news_section/006.php index 95e48aa77586..b848533ce78a 100644 --- a/user_guide_src/source/tutorial/news_section/006.php +++ b/user_guide_src/source/tutorial/news_section/006.php @@ -9,13 +9,13 @@ class News extends BaseController { // ... - public function show($slug = null) + public function show(?string $slug = null) { $model = model(NewsModel::class); $data['news'] = $model->getNews($slug); - if (empty($data['news'])) { + if ($data['news'] === null) { throw new PageNotFoundException('Cannot find the news item: ' . $slug); } diff --git a/user_guide_src/source/tutorial/static_pages.rst b/user_guide_src/source/tutorial/static_pages.rst index 7ae44927c316..8927a5e7cd7d 100644 --- a/user_guide_src/source/tutorial/static_pages.rst +++ b/user_guide_src/source/tutorial/static_pages.rst @@ -159,7 +159,7 @@ If the requested page doesn't exist, a "404 Page not found" error is shown. The first line in this method checks whether the page actually exists. PHP's native ``is_file()`` function is used to check whether the file is where it's expected to be. The ``PageNotFoundException`` is a CodeIgniter -exception that causes the default error page to show. +exception that causes the 404 Page Not Found error page to show. In the header template, the ``$title`` variable was used to customize the page title. The value of title is defined in this method, but instead of diff --git a/user_guide_src/source/tutorial/static_pages/001.php b/user_guide_src/source/tutorial/static_pages/001.php index 0cedb8e44906..9296014700ea 100644 --- a/user_guide_src/source/tutorial/static_pages/001.php +++ b/user_guide_src/source/tutorial/static_pages/001.php @@ -9,7 +9,7 @@ public function index() return view('welcome_message'); } - public function view($page = 'home') + public function view(string $page = 'home') { // ... } diff --git a/user_guide_src/source/tutorial/static_pages/002.php b/user_guide_src/source/tutorial/static_pages/002.php index 997f72b12101..9bd046ec3d21 100644 --- a/user_guide_src/source/tutorial/static_pages/002.php +++ b/user_guide_src/source/tutorial/static_pages/002.php @@ -8,7 +8,7 @@ class Pages extends BaseController { // ... - public function view($page = 'home') + public function view(string $page = 'home') { if (! is_file(APPPATH . 'Views/pages/' . $page . '.php')) { // Whoops, we don't have a page for that!