1- News section
2- ###############################################################################
1+ News Section
2+ ############
33
44In the last section, we went over some basic concepts of the framework
55by writing a class that references static pages. We cleaned up the URI by
66adding custom routing rules. Now it's time to introduce dynamic content
77and start using a database.
88
9- Create a database to work with
10- -------------------------------------------------------
9+ Create a Database to Work with
10+ ******************************
1111
1212The CodeIgniter installation assumes that you have set up an appropriate
1313database, as outlined in the :doc: `requirements </intro/requirements >`.
@@ -18,13 +18,7 @@ commands (mysql, MySQL Workbench, or phpMyAdmin).
1818You need to create a database that can be used for this tutorial,
1919and 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+
3837A note of interest: a "slug", in the context of web publishing, is a
3938user- 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
5350The local configuration file, ``.env ``, that you created when you installed
5451CodeIgniter, should have the database property settings uncommented and
5552set 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
6964Instead of writing database operations right in the controller, queries
7065should 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
106101returning 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
112107Now that the queries are written, the model should be tied to the views
113108that 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
176171Routing
177- -------------------------------------------------------
172+ *******
178173
179174Because of the wildcard routing rule created earlier, you need an extra
180175route to view the controller that you just made. Modify your routing file
0 commit comments