Skip to content

Commit daed3f8

Browse files
authored
Merge pull request #6769 from kenjis/fix-docs-tutorial-news_section
docs: improve tutorial news section
2 parents 31206da + 1f98cce commit daed3f8

4 files changed

Lines changed: 14 additions & 3 deletions

File tree

user_guide_src/source/tutorial/news_section.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ some additional tools to make working with data simpler. Add the
8888
following code to your model.
8989

9090
.. literalinclude:: news_section/002.php
91+
:lines: 11-18
9192

9293
With this code, you can perform two different queries. You can get all
9394
news records, or get a news item by its slug. You might have
@@ -113,7 +114,7 @@ a new ``News`` controller is defined. Create the new controller at
113114
.. literalinclude:: news_section/003.php
114115

115116
Looking at the code, you may see some similarity with the files we
116-
created earlier. First, it extends a core CodeIgniter class, ``Controller``,
117+
created earlier. First, it extends ``BaseController`` that extends a core CodeIgniter class, ``Controller``,
117118
which provides a couple of helper methods, and makes sure that you have
118119
access to the current ``Request`` and ``Response`` objects, as well as the
119120
``Logger`` class, for saving information to disk.
@@ -143,10 +144,10 @@ and add the next piece of code.
143144

144145
.. literalinclude:: news_section/005.php
145146

146-
.. note:: We are again using using ``esc()`` to help prevent XSS attacks.
147+
.. note:: We are again using using :php:func:`esc()` to help prevent XSS attacks.
147148
But this time we also passed "url" as a second parameter. That's because
148149
attack patterns are different depending on the context in which the output
149-
is used. You can read more about it :doc:`here </general/common_functions>`.
150+
is used.
150151

151152
Here, each news item is looped and displayed to the user. You can see we
152153
wrote our template in PHP mixed with HTML. If you prefer to use a template

user_guide_src/source/tutorial/news_section/002.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
<?php
22

3+
namespace App\Models;
4+
5+
use CodeIgniter\Model;
6+
37
class NewsModel extends Model
48
{
9+
protected $table = 'news';
10+
511
public function getNews($slug = false)
612
{
713
if ($slug === false) {

user_guide_src/source/tutorial/news_section/004.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ public function index()
1919
. view('news/overview')
2020
. view('templates/footer');
2121
}
22+
23+
// ...
2224
}

user_guide_src/source/tutorial/news_section/006.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
class News extends BaseController
88
{
9+
// ...
10+
911
public function view($slug = null)
1012
{
1113
$model = model(NewsModel::class);

0 commit comments

Comments
 (0)