Skip to content

Commit 88c8c4a

Browse files
authored
Merge pull request #5758 from kenjis/fix-docs-tutorial
docs: small fixes in tutorial
2 parents cf0d2bb + 4e4ab0b commit 88c8c4a

File tree

4 files changed

+43
-64
lines changed

4 files changed

+43
-64
lines changed

user_guide_src/source/tutorial/create_news_items.rst

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Create news items
1+
Create News Items
22
#################
33

44
You now know how you can read data from a database using CodeIgniter, but
@@ -7,7 +7,7 @@ you'll expand your news controller and model created earlier to include
77
this functionality.
88

99
Enable CSRF Filter
10-
------------------
10+
******************
1111

1212
Before creating a form, let's enable the CSRF protection.
1313

@@ -22,16 +22,14 @@ You can read more about the CSRF protection in :doc:`Security </libraries/securi
2222
because auto-routing permits any HTTP method to access a controller.
2323
Accessing the controller with a method you don't expect could bypass the filter.
2424

25-
Create a form
26-
-------------
25+
Create a Form
26+
*************
2727

2828
To input data into the database, you need to create a form where you can
2929
input the information to be stored. This means you'll be needing a form
3030
with two fields, one for the title and one for the text. You'll derive
3131
the slug from our title in the model. Create a new view at
32-
**app/Views/news/create.php**.
33-
34-
::
32+
**app/Views/news/create.php**::
3533

3634
<h2><?= esc($title) ?></h2>
3735

@@ -89,14 +87,12 @@ slug, perfect for creating URIs.
8987
After this, a view is loaded to display a success message. Create a view at
9088
**app/Views/news/success.php** and write a success message.
9189

92-
This could be as simple as:
93-
94-
::
90+
This could be as simple as::
9591

9692
News item created successfully.
9793

9894
Model Updating
99-
-------------------------------------------------------
95+
**************
10096

10197
The only thing that remains is ensuring that your model is set up
10298
to allow data to be saved properly. The ``save()`` method that was
@@ -119,7 +115,7 @@ This helps protect against Mass Assignment Vulnerabilities. If your model is
119115
handling your timestamps, you would also leave those out.
120116

121117
Routing
122-
-------------------------------------------------------
118+
*******
123119

124120
Before you can start adding news items into your CodeIgniter application
125121
you have to add an extra rule to **app/Config/Routes.php** file. Make sure your
@@ -144,7 +140,7 @@ Add some news and check out the different pages you made.
144140
:width: 45%
145141

146142
Congratulations
147-
-------------------------------------------------------
143+
***************
148144

149145
You just completed your first CodeIgniter4 application!
150146

user_guide_src/source/tutorial/index.rst

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This tutorial will primarily focus on:
2222
- Model-View-Controller basics
2323
- Routing basics
2424
- Form validation
25-
- Performing basic database queries using CodeIgniter's "Query Builder"
25+
- Performing basic database queries using CodeIgniter's Model
2626

2727
The entire tutorial is split up over several pages, each explaining a
2828
small part of the functionality of the CodeIgniter framework. You'll go
@@ -55,9 +55,7 @@ Getting Up and Running
5555

5656
You can download a release manually from the site, but for this tutorial we will
5757
use the recommended way and install the AppStarter package through Composer.
58-
From your command line type the following:
59-
60-
::
58+
From your command line type the following::
6159

6260
> composer create-project codeigniter4/appstarter ci-news
6361

@@ -88,9 +86,7 @@ The Welcome Page
8886
****************
8987

9088
Now point your browser to the correct URL you will be greeted by a welcome screen.
91-
Try it now by heading to the following URL:
92-
93-
::
89+
Try it now by heading to the following URL::
9490

9591
http://localhost:8080
9692

user_guide_src/source/tutorial/news_section.rst

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
News section
2-
###############################################################################
1+
News Section
2+
############
33

44
In the last section, we went over some basic concepts of the framework
55
by writing a class that references static pages. We cleaned up the URI by
66
adding custom routing rules. Now it's time to introduce dynamic content
77
and start using a database.
88

9-
Create a database to work with
10-
-------------------------------------------------------
9+
Create a Database to Work with
10+
******************************
1111

1212
The CodeIgniter installation assumes that you have set up an appropriate
1313
database, as outlined in the :doc:`requirements </intro/requirements>`.
@@ -18,13 +18,7 @@ commands (mysql, MySQL Workbench, or phpMyAdmin).
1818
You need to create a database that can be used for this tutorial,
1919
and then configure CodeIgniter to use it.
2020

21-
Using your database client, connect to your database and run the SQL command below (MySQL).
22-
Also, add some seed records. For now, we'll just show you the SQL statements needed
23-
to create the table, but you should be aware that this can be done programmatically
24-
once you are more familiar with CodeIgniter; you can read about :doc:`Migrations <../dbmgmt/migration>`
25-
and :doc:`Seeds <../dbmgmt/seeds>` to create more useful database setups later.
26-
27-
::
21+
Using your database client, connect to your database and run the SQL command below (MySQL)::
2822

2923
CREATE TABLE news (
3024
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
@@ -35,36 +29,37 @@ and :doc:`Seeds <../dbmgmt/seeds>` to create more useful database setups later.
3529
KEY slug (slug)
3630
);
3731

32+
Also, add some seed records. For now, we'll just show you the SQL statements needed
33+
to create the table, but you should be aware that this can be done programmatically
34+
once you are more familiar with CodeIgniter; you can read about :doc:`Migrations <../dbmgmt/migration>`
35+
and :doc:`Seeds <../dbmgmt/seeds>` to create more useful database setups later.
36+
3837
A note of interest: a "slug", in the context of web publishing, is a
3938
user- and SEO-friendly short text used in a URL to identify and describe a resource.
4039

41-
The seed records might be something like:
42-
43-
::
40+
The seed records might be something like::
4441

4542
INSERT INTO news VALUES
4643
(1,'Elvis sighted','elvis-sighted','Elvis was sighted at the Podunk internet cafe. It looked like he was writing a CodeIgniter app.'),
4744
(2,'Say it isn\'t so!','say-it-isnt-so','Scientists conclude that some programmers have a sense of humor.'),
4845
(3,'Caffeination, Yes!','caffeination-yes','World\'s largest coffee shop open onsite nested coffee shop for staff only.');
4946

50-
Connect to your database
51-
-------------------------------------------------------
47+
Connect to Your Database
48+
************************
5249

5350
The local configuration file, ``.env``, that you created when you installed
5451
CodeIgniter, should have the database property settings uncommented and
5552
set appropriately for the database you want to use. Make sure you've configured
56-
your database properly as described :doc:`here <../database/configuration>`.
57-
58-
::
53+
your database properly as described :doc:`here <../database/configuration>`::
5954

6055
database.default.hostname = localhost
6156
database.default.database = ci4tutorial
6257
database.default.username = root
6358
database.default.password = root
6459
database.default.DBDriver = MySQLi
6560

66-
Setting up your model
67-
-------------------------------------------------------
61+
Setting up Your Model
62+
*********************
6863

6964
Instead of writing database operations right in the controller, queries
7065
should be placed in a model, so they can easily be reused later. Models
@@ -106,8 +101,8 @@ that use the Query Builder to run their commands on the current table, and
106101
returning an array of results in the format of your choice. In this example,
107102
``findAll()`` returns an array of array.
108103

109-
Display the news
110-
-------------------------------------------------------
104+
Display the News
105+
****************
111106

112107
Now that the queries are written, the model should be tied to the views
113108
that are going to display the news items to the user. This could be done
@@ -174,7 +169,7 @@ The only thing left to do is create the corresponding view at
174169
.. literalinclude:: news_section/007.php
175170

176171
Routing
177-
-------------------------------------------------------
172+
*******
178173

179174
Because of the wildcard routing rule created earlier, you need an extra
180175
route to view the controller that you just made. Modify your routing file

user_guide_src/source/tutorial/static_pages.rst

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Static pages
2-
###############################################################################
1+
Static Pages
2+
############
33

44
.. note:: This tutorial assumes you've downloaded CodeIgniter and
55
:doc:`installed the framework <../installation/index>` in your
@@ -9,26 +9,22 @@ The first thing you're going to do is set up a **controller** to handle
99
static pages. A controller is simply a class that helps delegate work.
1010
It is the glue of your web application.
1111

12-
For example, when a call is made to:
13-
14-
::
12+
For example, when a call is made to::
1513

1614
http://example.com/news/latest/10
1715

1816
We might imagine that there is a controller named "news". The method
1917
being called on news would be "latest". The news method's job could be to
2018
grab 10 news items, and render them on the page. Very often in MVC,
21-
you'll see URL patterns that match:
22-
23-
::
19+
you'll see URL patterns that match::
2420

2521
http://example.com/[controller-class]/[controller-method]/[arguments]
2622

2723
As URL schemes become more complex, this may change. But for now, this
2824
is all we will need to know.
2925

30-
Let's make our first controller
31-
-------------------------------------------------------
26+
Let's Make our First Controller
27+
*******************************
3228

3329
Create a file at **app/Controllers/Pages.php** with the following
3430
code.
@@ -85,8 +81,8 @@ includes the following code::
8581
function. It's a global function provided by CodeIgniter to help prevent
8682
XSS attacks. You can read more about it :doc:`here </general/common_functions>`.
8783

88-
Adding logic to the controller
89-
-------------------------------------------------------
84+
Adding Logic to the Controller
85+
******************************
9086

9187
Earlier you set up a controller with a ``view()`` method. The method
9288
accepts one parameter, which is the name of the page to be loaded. The
@@ -131,16 +127,14 @@ view.
131127
:doc:`here </outgoing/views>`.
132128

133129
Running the App
134-
-------------------------------------------------------
130+
***************
135131

136132
Ready to test? You cannot run the app using PHP's built-in server,
137133
since it will not properly process the ``.htaccess`` rules that are provided in
138134
``public``, and which eliminate the need to specify "index.php/"
139135
as part of a URL. CodeIgniter has its own command that you can use though.
140136

141-
From the command line, at the root of your project:
142-
143-
::
137+
From the command line, at the root of your project::
144138

145139
> php spark serve
146140

@@ -177,14 +171,12 @@ controller you made above produces...
177171
+---------------------------------+-----------------------------------------------------------------+
178172

179173
Routing
180-
-------------------------------------------------------
174+
*******
181175

182176
The controller is now functioning!
183177

184178
Using custom routing rules, you have the power to map any URI to any
185-
controller and method, and break free from the normal convention:
186-
187-
::
179+
controller and method, and break free from the normal convention::
188180

189181
http://example.com/[controller-class]/[controller-method]/[arguments]
190182

0 commit comments

Comments
 (0)