admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
| 2 | <html>
|
| 3 | <head>
|
| 4 |
|
| 5 | <title>Code Igniter User Guide</title>
|
| 6 |
|
| 7 | <style type='text/css' media='all'>@import url('../userguide.css');</style>
|
| 8 | <link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
|
| 9 |
|
admin | 17a890d | 2006-09-27 20:42:42 +0000 | [diff] [blame] | 10 | <script type="text/javascript" src="../nav/nav.js"></script>
|
admin | 2296fc3 | 2006-09-27 21:07:02 +0000 | [diff] [blame] | 11 | <script type="text/javascript" src="../nav/prototype.lite.js"></script>
|
admin | 17a890d | 2006-09-27 20:42:42 +0000 | [diff] [blame] | 12 | <script type="text/javascript" src="../nav/moo.fx.js"></script>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 13 | <script type="text/javascript">
|
| 14 | window.onload = function() {
|
| 15 | myHeight = new fx.Height('nav', {duration: 400});
|
| 16 | myHeight.hide();
|
| 17 | }
|
| 18 | </script>
|
| 19 |
|
| 20 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
| 21 | <meta http-equiv='expires' content='-1' />
|
| 22 | <meta http-equiv= 'pragma' content='no-cache' />
|
| 23 | <meta name='robots' content='all' />
|
| 24 | <meta name='author' content='Rick Ellis' />
|
| 25 | <meta name='description' content='Code Igniter User Guide' />
|
| 26 |
|
| 27 | </head>
|
| 28 | <body>
|
| 29 |
|
| 30 | <!-- START NAVIGATION -->
|
| 31 | <div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
|
| 32 | <div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle.jpg" width="153" height="44" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
|
| 33 | <div id="masthead">
|
| 34 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 35 | <tr>
|
admin | 10c3f41 | 2006-10-08 07:21:12 +0000 | [diff] [blame^] | 36 | <td><h1>Code Igniter User Guide Version 1.5.0b1</h1></td>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 37 | <td id="breadcrumb_right"><a href="../toc.html">Full Table of Contents</a></td>
|
| 38 | </tr>
|
| 39 | </table>
|
| 40 | </div>
|
| 41 | <!-- END NAVIGATION -->
|
| 42 |
|
| 43 |
|
| 44 | <!-- START BREADCRUMB -->
|
| 45 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 46 | <tr>
|
| 47 | <td id="breadcrumb">
|
| 48 | <a href="http://www.codeigniter.com/">Code Igniter Home</a> ›
|
| 49 | <a href="../index.html">User Guide Home</a> ›
|
| 50 | URLS
|
| 51 | </td>
|
| 52 | <td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="www.codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
|
| 53 | </tr>
|
| 54 | </table>
|
| 55 | <!-- END BREADCRUMB -->
|
| 56 |
|
| 57 | <br clear="all" />
|
| 58 |
|
| 59 |
|
| 60 | <!-- START CONTENT -->
|
| 61 | <div id="content">
|
| 62 |
|
| 63 |
|
| 64 | <h1>Code Igniter URLs</h1>
|
| 65 |
|
| 66 | <p>By default, URLs in Code Igniter are designed to be search-engine and human friendly. Rather than using the standard "query string"
|
| 67 | approach to URLs that is synonymous with dynamic systems, Code Igniter uses a <strong>segment-based</strong> approach:</p>
|
| 68 |
|
| 69 | <code>www.your-site.com/<var>news</var>/<dfn>article</dfn>/<samp>my_article</samp></code>
|
| 70 |
|
| 71 | <p class="important"><strong>Note:</strong> Query string URLs can be optionally enabled, as described below.</p>
|
| 72 |
|
| 73 | <h2>URI Segments</h2>
|
| 74 |
|
| 75 | <p>The segments in the URL, in following with the Model-View-Controller approach, usually represent:</p>
|
| 76 |
|
| 77 | <code>www.your-site.com/<var>class</var>/<dfn>function</dfn>/<samp>ID</samp></code>
|
| 78 |
|
| 79 | <ol>
|
| 80 | <li>The first segment represents the controller <strong>class</strong> that should be invoked.</li>
|
| 81 | <li>The second segment represents the class <strong>function</strong>, or method, that should be called.</li>
|
| 82 | <li>The third, and any additional segments, represent the ID and any variables that will be passed to the controller.</p>
|
| 83 | </ol>
|
| 84 |
|
| 85 | <p>The <a href="../libraries/uri.html">URI Class</a> and the <a href="../helpers/url_helper.html">URL Helper</a>
|
| 86 | contain functions that make it easy to work with your URI data. In addition, your URLs can be remapped using the
|
| 87 | <a href="routing.html">URI Routing</a> feature for more flexibility.</p>
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 | <h2>Removing the index.php file</h2>
|
| 92 |
|
| 93 | <p>By default, the <strong>index.php</strong> file will be included in your URLs:
|
| 94 |
|
| 95 | <code>www.your-site.com/<var>index.php</var>/news/article/my_article</code>
|
| 96 |
|
| 97 | <p>You can easily remove this file by using a .htaccess file with some simple rules. Here is an example
|
| 98 | of such a file, using the "negative" method in which everything is redirected except the specified items:</p>
|
| 99 |
|
| 100 | <code>RewriteEngine on<br />
|
| 101 | RewriteCond $1 !^(index\.php|images|robots\.txt)<br />
|
| 102 | RewriteRule ^(.*)$ /index.php/$1 [L]</code>
|
| 103 |
|
| 104 | <p>In the above example, any HTTP request other than those for index.php, images, and robots.txt is treated as
|
| 105 | a request for your index.php file.</p>
|
| 106 |
|
| 107 |
|
| 108 | <h2>Adding a URL Suffix</h2>
|
| 109 |
|
| 110 | <p>In your <dfn>config/config.php</dfn> file you can specify a suffix that will be added to all URLs generated
|
| 111 | by Code Igniter. For example, if a URL is this:
|
| 112 |
|
| 113 | <code>www.your-site.com/index.php/products/view/shoes</code>
|
| 114 |
|
| 115 | <p>You can optionaally add a suffix, like <kbd>.html</kbd>, making the page appear to be of a certain type:</p>
|
| 116 |
|
| 117 | <code>www.your-site.com/index.php/products/view/shoes.html</code>
|
| 118 |
|
| 119 |
|
| 120 | <h2>Enabling Query Strings</h2>
|
| 121 |
|
| 122 | <p>In some cases you might prefer to use query strings URLs:</p>
|
| 123 |
|
| 124 | <code>index.php?c=products&m=view&id=345</code>
|
| 125 |
|
| 126 | <p>Code Igniter optionally supports this capability, which can be enabled in your <dfn>application/config.php</dfn> file. If you
|
| 127 | open your config file you'll see these items:</p>
|
| 128 |
|
| 129 | <code>$config['enable_query_strings'] = FALSE;<br />
|
| 130 | $config['controller_trigger'] = 'c';<br />
|
| 131 | $config['function_trigger'] = 'm';</code>
|
| 132 |
|
| 133 | <p>If you change "enable_query_strings" to TRUE this feature will become active. Your controllers and functions will then
|
| 134 | be accessible using the "trigger" words you've set to invoke your controllers and methods:</p>
|
| 135 |
|
| 136 | <code>index.php?c=controller&m=method</code>
|
| 137 |
|
| 138 | <p class="important"><strong>Please note:</strong> If you are using query strings you will have to build your own URLs, rather than utilizing
|
| 139 | the URL helpers (and other helpers that generate URLs, like some of the form helpers) as these are designed to work with
|
| 140 | segment based URLs.</p>
|
| 141 |
|
| 142 |
|
| 143 | </div>
|
| 144 | <!-- END CONTENT -->
|
| 145 |
|
| 146 |
|
| 147 | <div id="footer">
|
| 148 | <p>
|
| 149 | Previous Topic: <a href="index.html">Getting Started</a>
|
| 150 | ·
|
| 151 | <a href="#top">Top of Page</a> ·
|
| 152 | <a href="../index.html">User Guide Home</a> ·
|
| 153 | Next Topic: <a href="controllers.html">Controllers</a>
|
| 154 | <p>
|
| 155 | <p><a href="http://www.codeigniter.com">Code Igniter</a> · Copyright © 2006 · <a href="http://www.pmachine.com">pMachine, Inc.</a></p>
|
| 156 | </div>
|
| 157 |
|
| 158 | </body>
|
| 159 | </html> |