Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions user_guide_src/source/tutorial/create_news_items/004.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

// ...
5 changes: 4 additions & 1 deletion user_guide_src/source/tutorial/news_section.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 to 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
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/tutorial/news_section/004.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function index()
];

return view('templates/header', $data)
. view('news/overview')
. view('news/index')
. view('templates/footer');
}

Expand Down
3 changes: 2 additions & 1 deletion user_guide_src/source/tutorial/news_section/006.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Controllers;

use App\Models\NewsModel;
use CodeIgniter\Exceptions\PageNotFoundException;

class News extends BaseController
{
Expand All @@ -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'];
Expand Down
11 changes: 7 additions & 4 deletions user_guide_src/source/tutorial/news_section/008.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

// ...
5 changes: 4 additions & 1 deletion user_guide_src/source/tutorial/static_pages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -144,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.
Expand Down
4 changes: 3 additions & 1 deletion user_guide_src/source/tutorial/static_pages/002.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Controllers;

use CodeIgniter\Exceptions\PageNotFoundException; // Add this line

class Pages extends BaseController
{
// ...
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions user_guide_src/source/tutorial/static_pages/004.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

$routes->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']);