Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tut #1281

Merged
merged 2 commits into from
Oct 2, 2018
Merged

Tut #1281

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
2 changes: 1 addition & 1 deletion application/Config/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

// We get a performance increase by specifying the default
// route since we don't have to scan directories.
$routes->add('/', 'Home::index');
$routes->get('/', 'Home::index');

/**
* --------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion public/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# ----------------------------------------------------------------------

# Sets the environment that CodeIgniter runs under.
SetEnv CI_ENVIRONMENT development
# SetEnv CI_ENVIRONMENT development

# ----------------------------------------------------------------------
# UTF-8 encoding
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/tutorial/news_section.rst
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ with a slug to the ``view()`` method in the ``News`` controller.

$routes->get('news/(:segment)', 'News::view/$1');
$routes->get('news', 'News::index');
$routes->add('(:any)', 'Pages::view/$1');
$routes->get('(:any)', 'Pages::view/$1');

Point your browser to your document root, followed by index.php/news and
watch your news page.
25 changes: 11 additions & 14 deletions user_guide_src/source/tutorial/static_pages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Running the App
---------------

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

Expand Down Expand Up @@ -170,7 +170,7 @@ controller you made above produces...
Routing
-------

The controller is now functioning!
The controller is now functioning!

Using custom routing rules, you have the power to map any URI to any
controller and method, and break free from the normal convention:
Expand All @@ -182,17 +182,22 @@ section of the configuration file.

The only uncommented line there to start with should be:::

$routes->add('/', 'Home::index');
$routes->get('/', 'Home::index');

This directive says that any incoming request without any content
specified should be handled by the ``index`` method inside the ``Home`` controller.

Add the following two lines, in front of the route directive for '/'.
Set the default controller to run your new method:

::

$routes->setDefaultController('Pages/view');
$routes->add('(:any)', 'Pages::view/$1');
$routes->setDefaultController('Pages/view');

Add the following line, **after** the route directive for '/'.

::

$routes->get('(:any)', 'Pages::view/$1');

CodeIgniter reads its routing rules from top to bottom and routes the
request to the first matching rule. Each rule is a regular expression
Expand All @@ -208,13 +213,5 @@ Here, the second rule in the ``$routes`` array matches **any** request
using the wildcard string ``(:any)``. and passes the parameter to the
``view()`` method of the ``Pages`` class.

In order for the default controller to be used, though, you have to make
sure that no other routes are defined that handle the route. By default,
the Routes file **does** have a route that handles the site root (/).
Delete the following route to make sure that the Pages controller handles
our home page::

$routes->add('/', 'Home::index');

Now visit ``index.php/about``. Did it get routed correctly to the ``view()``
method in the pages controller? Awesome!