From fa236f79bf9debbf6acd751d17c0c94f39ab637b Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 3 Dec 2022 10:04:19 +0900 Subject: [PATCH 1/4] docs: change view file name Name by the controller method. --- user_guide_src/source/tutorial/news_section.rst | 2 +- user_guide_src/source/tutorial/news_section/004.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/tutorial/news_section.rst b/user_guide_src/source/tutorial/news_section.rst index 02df7d1a5e2b..08395dda957a 100644 --- a/user_guide_src/source/tutorial/news_section.rst +++ b/user_guide_src/source/tutorial/news_section.rst @@ -143,7 +143,7 @@ the views. Modify the ``index()`` method to look like this: The code above gets all news records from the model and assigns it to a variable. The value for the title is also assigned to the ``$data['title']`` element and all data is passed to the views. You now need to create a -view to render the news items. Create **app/Views/news/overview.php** +view to render the news items. Create **app/Views/news/index.php** and add the next piece of code. .. literalinclude:: news_section/005.php diff --git a/user_guide_src/source/tutorial/news_section/004.php b/user_guide_src/source/tutorial/news_section/004.php index 76ef80caf25e..625acaf805cf 100644 --- a/user_guide_src/source/tutorial/news_section/004.php +++ b/user_guide_src/source/tutorial/news_section/004.php @@ -16,7 +16,7 @@ public function index() ]; return view('templates/header', $data) - . view('news/overview') + . view('news/index') . view('templates/footer'); } From 3d00d96c183ad9be18c97b7df4b0f6284b260a34 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 3 Dec 2022 10:13:25 +0900 Subject: [PATCH 2/4] docs: use use keyword --- user_guide_src/source/tutorial/news_section.rst | 3 +++ user_guide_src/source/tutorial/news_section/006.php | 3 ++- user_guide_src/source/tutorial/static_pages.rst | 3 +++ user_guide_src/source/tutorial/static_pages/002.php | 4 +++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/tutorial/news_section.rst b/user_guide_src/source/tutorial/news_section.rst index 08395dda957a..7e539e8ddb3f 100644 --- a/user_guide_src/source/tutorial/news_section.rst +++ b/user_guide_src/source/tutorial/news_section.rst @@ -166,6 +166,9 @@ add some code to the controller and create a new view. Go back to the .. literalinclude:: news_section/006.php +Don't forget add ``use CodeIgniter\Exceptions\PageNotFoundException;`` to import +the ``PageNotFoundException`` class. + Instead of calling the ``getNews()`` method without a parameter, the ``$slug`` variable is passed, so it will return the specific news item. The only thing left to do is create the corresponding view at diff --git a/user_guide_src/source/tutorial/news_section/006.php b/user_guide_src/source/tutorial/news_section/006.php index 260fbcc6465b..657211792f46 100644 --- a/user_guide_src/source/tutorial/news_section/006.php +++ b/user_guide_src/source/tutorial/news_section/006.php @@ -3,6 +3,7 @@ namespace App\Controllers; use App\Models\NewsModel; +use CodeIgniter\Exceptions\PageNotFoundException; class News extends BaseController { @@ -15,7 +16,7 @@ public function view($slug = null) $data['news'] = $model->getNews($slug); if (empty($data['news'])) { - throw new \CodeIgniter\Exceptions\PageNotFoundException('Cannot find the news item: ' . $slug); + throw new PageNotFoundException('Cannot find the news item: ' . $slug); } $data['title'] = $data['news']['title']; diff --git a/user_guide_src/source/tutorial/static_pages.rst b/user_guide_src/source/tutorial/static_pages.rst index d83bbd98d7cb..7435b9a7a590 100644 --- a/user_guide_src/source/tutorial/static_pages.rst +++ b/user_guide_src/source/tutorial/static_pages.rst @@ -89,6 +89,9 @@ in the ``Pages`` controller created above: .. literalinclude:: static_pages/002.php +And add ``use CodeIgniter\Exceptions\PageNotFoundException;`` after the ``namespace`` line +to import the ``PageNotFoundException`` class. + Now, when the requested page does exist, it is loaded, including the header and footer, and returned to the user. If a controller returns a string, it is displayed to the user. diff --git a/user_guide_src/source/tutorial/static_pages/002.php b/user_guide_src/source/tutorial/static_pages/002.php index eda5c744a001..997f72b12101 100644 --- a/user_guide_src/source/tutorial/static_pages/002.php +++ b/user_guide_src/source/tutorial/static_pages/002.php @@ -2,6 +2,8 @@ namespace App\Controllers; +use CodeIgniter\Exceptions\PageNotFoundException; // Add this line + class Pages extends BaseController { // ... @@ -10,7 +12,7 @@ public function view($page = 'home') { if (! is_file(APPPATH . 'Views/pages/' . $page . '.php')) { // Whoops, we don't have a page for that! - throw new \CodeIgniter\Exceptions\PageNotFoundException($page); + throw new PageNotFoundException($page); } $data['title'] = ucfirst($page); // Capitalize the first letter From fb0a5bc6fcd1eadbaba5a9ddba28661bc961e234 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 3 Dec 2022 10:31:28 +0900 Subject: [PATCH 3/4] docs: use Array Callable Syntax for routing --- .../source/tutorial/create_news_items/004.php | 13 ++++++++----- user_guide_src/source/tutorial/news_section/008.php | 11 +++++++---- user_guide_src/source/tutorial/static_pages.rst | 2 +- user_guide_src/source/tutorial/static_pages/004.php | 6 ++++-- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/user_guide_src/source/tutorial/create_news_items/004.php b/user_guide_src/source/tutorial/create_news_items/004.php index 8a0905770c82..7df16092c80b 100644 --- a/user_guide_src/source/tutorial/create_news_items/004.php +++ b/user_guide_src/source/tutorial/create_news_items/004.php @@ -2,10 +2,13 @@ // ... -$routes->match(['get', 'post'], 'news/create', 'News::create'); -$routes->get('news/(:segment)', 'News::view/$1'); -$routes->get('news', 'News::index'); -$routes->get('pages', 'Pages::index'); -$routes->get('(:any)', 'Pages::view/$1'); +use App\Controllers\News; +use App\Controllers\Pages; + +$routes->match(['get', 'post'], 'news/create', [News::class, 'create']); +$routes->get('news/(:segment)', [News::class, 'view']); +$routes->get('news', [News::class, 'index']); +$routes->get('pages', [Pages::class, 'index']); +$routes->get('(:any)', [Pages::class, 'view']); // ... diff --git a/user_guide_src/source/tutorial/news_section/008.php b/user_guide_src/source/tutorial/news_section/008.php index 4ba41638ef7f..45c729c8157b 100644 --- a/user_guide_src/source/tutorial/news_section/008.php +++ b/user_guide_src/source/tutorial/news_section/008.php @@ -2,9 +2,12 @@ // ... -$routes->get('news/(:segment)', 'News::view/$1'); -$routes->get('news', 'News::index'); -$routes->get('pages', 'Pages::index'); -$routes->get('(:any)', 'Pages::view/$1'); +use App\Controllers\News; +use App\Controllers\Pages; + +$routes->get('news/(:segment)', [News::class, 'view']); +$routes->get('news', [News::class, 'index']); +$routes->get('pages', [Pages::class, 'index']); +$routes->get('(:any)', [Pages::class, 'view']); // ... diff --git a/user_guide_src/source/tutorial/static_pages.rst b/user_guide_src/source/tutorial/static_pages.rst index 7435b9a7a590..888d0ccd4a15 100644 --- a/user_guide_src/source/tutorial/static_pages.rst +++ b/user_guide_src/source/tutorial/static_pages.rst @@ -147,7 +147,7 @@ Add the following lines, **after** the route directive for '/'. CodeIgniter reads its routing rules from top to bottom and routes the request to the first matching rule. Each rule is a regular expression -(left-side) mapped to a controller and method name separated by slashes +(left-side) mapped to a controller and method name (right-side). When a request comes in, CodeIgniter looks for the first match, and calls the appropriate controller and method, possibly with arguments. diff --git a/user_guide_src/source/tutorial/static_pages/004.php b/user_guide_src/source/tutorial/static_pages/004.php index a48a8caf18cb..a1e175bd4822 100644 --- a/user_guide_src/source/tutorial/static_pages/004.php +++ b/user_guide_src/source/tutorial/static_pages/004.php @@ -1,4 +1,6 @@ get('pages', 'Pages::index'); -$routes->get('(:any)', 'Pages::view/$1'); +use App\Controllers\Pages; + +$routes->get('pages', [Pages::class, 'index']); +$routes->get('(:any)', [Pages::class, 'view']); From c5c0287ea277d0d7e4c836bf105018b72241d4f4 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 4 Dec 2022 06:46:20 +0900 Subject: [PATCH 4/4] docs: fix by proofreading Co-authored-by: John Paul E. Balandan, CPA --- user_guide_src/source/tutorial/news_section.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/tutorial/news_section.rst b/user_guide_src/source/tutorial/news_section.rst index 7e539e8ddb3f..912b895c00b0 100644 --- a/user_guide_src/source/tutorial/news_section.rst +++ b/user_guide_src/source/tutorial/news_section.rst @@ -166,7 +166,7 @@ add some code to the controller and create a new view. Go back to the .. literalinclude:: news_section/006.php -Don't forget add ``use CodeIgniter\Exceptions\PageNotFoundException;`` to import +Don't forget to add ``use CodeIgniter\Exceptions\PageNotFoundException;`` to import the ``PageNotFoundException`` class. Instead of calling the ``getNews()`` method without a parameter, the