Skip to content

Commit 2a53b62

Browse files
committed
Add better explanation to serving in tutorial
1 parent 5128fa4 commit 2a53b62

2 files changed

Lines changed: 45 additions & 11 deletions

File tree

user_guide_src/source/tutorial/index.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ through the following pages:
3333
- :doc:`Conclusion <conclusion>`, which will give you some pointers on
3434
further reading and other resources.
3535

36-
.. caution:: Using PHP's built-in web server is likely to cause problems,
37-
as it does not process the `.htaccess` file used to properly handle requests.
38-
Use your favorite web server instead.
39-
40-
4136
Enjoy your exploration of the CodeIgniter framework.
4237

4338
.. toctree::

user_guide_src/source/tutorial/static_pages.rst

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,60 @@ view.
134134
match the case of the actual directory and file itself or the system will
135135
throw errors on case-sensitive platforms.
136136

137+
Running the App
138+
---------------
139+
140+
Ready to test? You cannot run the app using PHP's built-in server,
141+
since it will not properly process the ``.htaccess`` rules that are provided in
142+
``public``, and which eliminate the need to specify "index.php/"
143+
as part of a URL. CodeIgniter has its own command that you can use though.
144+
145+
From the command line, at the root of your project:
146+
147+
php spark serve
148+
149+
will start a web server, accessible on port 8080. If you set the location field
150+
in your browser to ``localhost:8080``, you should see the CodeIgniter welcome page.
151+
152+
You can now try several URLs in the browser location field, to see what the `Pages`
153+
controller you made above produces...
154+
155+
- ``localhost:8080/pages`` will show the results from the `index` method
156+
inside our `Pages` controller, which is to display the CodeIgniter "welcome" page,
157+
because "index" is the default controller method
158+
- ``localhost:8080/pages/index`` will also show the CodeIgniter "welcome" page,
159+
because we explicitly asked for the "index" methid
160+
- ``localhost:8080/pages/view`` will show the "home" page that you made above,
161+
because it is the default "page" parameter to the `view()` method.
162+
- ``localhost:8080/pages/view/home`` will also show the "home" page that you made above,
163+
because we explicitly asked for it
164+
- ``localhost:8080/pages/view/about`` will show the "about" page that you made above,
165+
because we explicitly asked for it
166+
- ``localhost:8080/pages/view/shop`` will show a "404 - File Not Found" error page,
167+
because there is no `application/Views/pages/shop.php`
168+
169+
137170
Routing
138171
-------
139172

140-
The controller is now functioning! Point your browser to
141-
``[your-site-url]index.php/pages/view`` to see your page. When you visit
142-
``index.php/pages/view/about`` you'll see the about page, again including
143-
the header and footer.
173+
The controller is now functioning!
144174

145175
Using custom routing rules, you have the power to map any URI to any
146176
controller and method, and break free from the normal convention:
147177
``http://example.com/[controller-class]/[controller-method]/[arguments]``
148178

149179
Let's do that. Open the routing file located at
150-
*application/Config/Routes.php* and add the following two lines.
151-
Remove all other code that adds any element in the ``$route`` items.
180+
*application/Config/Routes.php* and look for the "Route Definitions"
181+
section of the configuration file.
182+
183+
The only uncommented line there to start with should be:::
184+
185+
$routes->add('/', 'Home::index');
186+
187+
This directive says that any incoming request without any content
188+
specified should be handled by the ``index`` method inside the ``Home`` controller.
189+
190+
Add the following two lines, in front of the route directive for '/'.
152191

153192
::
154193

0 commit comments

Comments
 (0)