From 4282c7a3b889533d3c1c8befcfc56f828bc667b4 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 21 Mar 2024 10:36:55 +0900 Subject: [PATCH 1/5] docs: replace empty() Using empty() is not a good practice. --- user_guide_src/source/tutorial/news_section/005.php | 2 +- user_guide_src/source/tutorial/news_section/006.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/tutorial/news_section/005.php b/user_guide_src/source/tutorial/news_section/005.php index 39db0a4319f7..a04c1dddb28b 100644 --- a/user_guide_src/source/tutorial/news_section/005.php +++ b/user_guide_src/source/tutorial/news_section/005.php @@ -1,6 +1,6 @@

- + diff --git a/user_guide_src/source/tutorial/news_section/006.php b/user_guide_src/source/tutorial/news_section/006.php index 95e48aa77586..f4b3e1d140e2 100644 --- a/user_guide_src/source/tutorial/news_section/006.php +++ b/user_guide_src/source/tutorial/news_section/006.php @@ -15,7 +15,7 @@ public function show($slug = null) $data['news'] = $model->getNews($slug); - if (empty($data['news'])) { + if ($data['news'] === null) { throw new PageNotFoundException('Cannot find the news item: ' . $slug); } From a7fc049cef6789b34c388d2a2f253b8b2066f3b9 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 21 Mar 2024 10:37:26 +0900 Subject: [PATCH 2/5] docs: rename news to news_list Make it better name. --- user_guide_src/source/tutorial/news_section/003.php | 2 +- user_guide_src/source/tutorial/news_section/004.php | 4 ++-- user_guide_src/source/tutorial/news_section/005.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/user_guide_src/source/tutorial/news_section/003.php b/user_guide_src/source/tutorial/news_section/003.php index 22b24577b01e..2871c050cfea 100644 --- a/user_guide_src/source/tutorial/news_section/003.php +++ b/user_guide_src/source/tutorial/news_section/003.php @@ -10,7 +10,7 @@ public function index() { $model = model(NewsModel::class); - $data['news'] = $model->getNews(); + $data['news_list'] = $model->getNews(); } public function show($slug = null) 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 a04c1dddb28b..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 @@

- + - +

From ae0eb2f4be1ae22a748404c195e90b6537e23961 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 21 Mar 2024 10:43:29 +0900 Subject: [PATCH 3/5] docs: add typehint to controller methods --- user_guide_src/source/tutorial/news_section/003.php | 2 +- user_guide_src/source/tutorial/news_section/006.php | 2 +- user_guide_src/source/tutorial/static_pages/001.php | 2 +- user_guide_src/source/tutorial/static_pages/002.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/user_guide_src/source/tutorial/news_section/003.php b/user_guide_src/source/tutorial/news_section/003.php index 2871c050cfea..fe5c0378bfa4 100644 --- a/user_guide_src/source/tutorial/news_section/003.php +++ b/user_guide_src/source/tutorial/news_section/003.php @@ -13,7 +13,7 @@ public function index() $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/006.php b/user_guide_src/source/tutorial/news_section/006.php index f4b3e1d140e2..b848533ce78a 100644 --- a/user_guide_src/source/tutorial/news_section/006.php +++ b/user_guide_src/source/tutorial/news_section/006.php @@ -9,7 +9,7 @@ class News extends BaseController { // ... - public function show($slug = null) + public function show(?string $slug = null) { $model = model(NewsModel::class); 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! From 79f51a81ace7617cc2cd9cc4845827a28c4e6f16 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 21 Mar 2024 10:43:56 +0900 Subject: [PATCH 4/5] docs: add PHPDoc types --- user_guide_src/source/tutorial/news_section.rst | 2 +- user_guide_src/source/tutorial/news_section/002.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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) { From 31b484facf550dcf90ef4a46e2aeb43745058ce0 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 21 Mar 2024 10:53:47 +0900 Subject: [PATCH 5/5] docs: make description more accurate --- user_guide_src/source/tutorial/static_pages.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/tutorial/static_pages.rst b/user_guide_src/source/tutorial/static_pages.rst index db3382245195..633798d2254f 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