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">
|
Derek Allard | afd99ac | 2008-01-19 19:59:14 +0000 | [diff] [blame] | 2 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 3 | <head>
|
| 4 |
|
Derek Allard | 404e35d | 2007-08-07 01:00:45 +0000 | [diff] [blame] | 5 | <title>CodeIgniter User Guide : URL Helper</title>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 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>
|
Derek Allard | b341237 | 2007-10-25 12:15:16 +0000 | [diff] [blame] | 13 | <script type="text/javascript" src="../nav/user_guide_menu.js"></script>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 14 |
|
| 15 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
| 16 | <meta http-equiv='expires' content='-1' />
|
| 17 | <meta http-equiv= 'pragma' content='no-cache' />
|
| 18 | <meta name='robots' content='all' />
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 19 | <meta name='author' content='ExpressionEngine Dev Team' />
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 20 | <meta name='description' content='CodeIgniter User Guide' />
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 21 |
|
| 22 | </head>
|
| 23 | <body>
|
| 24 |
|
| 25 | <!-- START NAVIGATION -->
|
| 26 | <div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
|
| 27 | <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>
|
| 28 | <div id="masthead">
|
| 29 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 30 | <tr>
|
Derek Allard | 197d10b | 2008-02-12 04:20:38 +0000 | [diff] [blame] | 31 | <td><h1>CodeIgniter User Guide Version 1.6.1</h1></td>
|
admin | c0d5d52 | 2006-10-30 19:40:35 +0000 | [diff] [blame] | 32 | <td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 33 | </tr>
|
| 34 | </table>
|
| 35 | </div>
|
| 36 | <!-- END NAVIGATION -->
|
| 37 |
|
| 38 |
|
| 39 | <!-- START BREADCRUMB -->
|
| 40 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 41 | <tr>
|
| 42 | <td id="breadcrumb">
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 43 | <a href="http://codeigniter.com/">CodeIgniter Home</a> ›
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 44 | <a href="../index.html">User Guide Home</a> ›
|
| 45 | URL Helper
|
| 46 | </td>
|
Derek Allard | bc03091 | 2007-06-24 18:25:29 +0000 | [diff] [blame] | 47 | <td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="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>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 48 | </tr>
|
| 49 | </table>
|
| 50 | <!-- END BREADCRUMB -->
|
| 51 |
|
| 52 | <br clear="all" />
|
| 53 |
|
| 54 |
|
| 55 | <!-- START CONTENT -->
|
| 56 | <div id="content">
|
| 57 |
|
| 58 |
|
| 59 | <h1>URL Helper</h1>
|
| 60 |
|
| 61 | <p>The URL Helper file contains functions that assist in working with URLs.</p>
|
| 62 |
|
| 63 |
|
| 64 | <h2>Loading this Helper</h2>
|
| 65 |
|
| 66 | <p>This helper is loaded using the following code:</p>
|
| 67 | <code>$this->load->helper('url');</code>
|
| 68 |
|
| 69 | <p>The following functions are available:</p>
|
| 70 |
|
| 71 | <h2>site_url()</h2>
|
| 72 |
|
| 73 | <p>Returns your site URL, as specified in your config file. The index.php file (or whatever you have set as your
|
| 74 | site <dfn>index_page</dfn> in your config file) will be added to the URL, as will any URI segments you pass to the function.</p>
|
| 75 |
|
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 76 | <p>You are encouraged to use this function any time you need to generate a local URL so that your pages become more portable
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 77 | in the event your URL changes.</p>
|
| 78 |
|
| 79 | <p>Segments can be optionally passed to the function as a string or an array. Here is a string example:</p>
|
| 80 |
|
| 81 | <code>echo site_url("news/local/123");</code>
|
| 82 |
|
| 83 | <p>The above example would return something like: http://www.your-site.com/index.php/news/local/123</p>
|
| 84 |
|
| 85 | <p>Here is an example of segments passed as an array:</p>
|
| 86 |
|
| 87 | <code>
|
| 88 | $segments = array('news', 'local', '123');<br />
|
| 89 | <br />
|
| 90 | echo site_url($segments);</code>
|
| 91 |
|
| 92 |
|
| 93 | <h2>base_url()</h2>
|
| 94 | <p>Returns your site base URL, as specified in your config file. Example:</p>
|
| 95 | <code>echo base_url();</code>
|
| 96 |
|
| 97 |
|
| 98 | <h2>index_page()</h2>
|
| 99 | <p>Returns your site "index" page, as specified in your config file. Example:</p>
|
| 100 | <code>echo index_page();</code>
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 | <h2>anchor()</h2>
|
| 105 |
|
| 106 | <p>Creates a standard HTML anchor link based on your local site URL:</p>
|
| 107 |
|
| 108 | <code><a href="http://www.your-site.com">Click Here</a></code>
|
| 109 |
|
| 110 | <p>The tag has three optional parameters:</p>
|
| 111 |
|
| 112 | <code>anchor(<var>uri segments</var>, <var>text</var>, <var>attributes</var>)</code>
|
| 113 |
|
| 114 | <p>The first parameter can contain any segments you wish appended to the URL. As with the <dfn>site_url()</dfn> function above,
|
admin | b071bb5 | 2006-08-26 19:28:37 +0000 | [diff] [blame] | 115 | segments can be a string or an array.</p>
|
| 116 |
|
| 117 | <p><strong>Note:</strong> If you are building links that are internal to your application do not include the base URL (http://...). This
|
| 118 | will be added automatically from the information specified in your config file. Include only the URI segments you wish appended to the URL.</p>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 119 |
|
| 120 | <p>The second segment is the text you would like the link to say. If you leave it blank, the URL will be used.</p>
|
| 121 |
|
| 122 | <p>The third parameter can contain a list of attributes you would like added to the link. The attributes can be a simple string or an associative array.</p>
|
| 123 |
|
| 124 | <p>Here are some examples:</p>
|
| 125 |
|
Derek Allard | c4e9dc9 | 2007-02-06 19:52:30 +0000 | [diff] [blame] | 126 | <code>echo anchor('news/local/123', 'My News');</code>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 127 |
|
| 128 | <p>Would produce: <a href="http://www.your-site.com/index.php/news/local/123" title="My News">My News</a></p>
|
| 129 |
|
Derek Allard | c4e9dc9 | 2007-02-06 19:52:30 +0000 | [diff] [blame] | 130 | <code>echo anchor('news/local/123', 'My News', array('title' => 'The best news!'));</code>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 131 |
|
| 132 | <p>Would produce: <a href="http://www.your-site.com/index.php/news/local/123" title="The best news!">My News</a></p>
|
| 133 |
|
| 134 |
|
| 135 | <h2>anchor_popup()</h2>
|
| 136 |
|
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 137 | <p>Nearly identical to the <dfn>anchor()</dfn> function except that it opens the URL in a new window.
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 138 |
|
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 139 | You can specify JavaScript window attributes in the third parameter to control how the window is opened. If
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 140 | the third parameter is not set it will simply open a new window with your own browser settings. Here is an example
|
| 141 | with attributes:</p>
|
| 142 |
|
| 143 | <code>
|
| 144 |
|
| 145 | $atts = array(<br />
|
| 146 | 'width' => '800',<br />
|
| 147 | 'height' => '600',<br />
|
| 148 | 'scrollbars' => 'yes',<br />
|
| 149 | 'status' => 'yes',<br />
|
| 150 | 'resizable' => 'yes',<br />
|
| 151 | 'screenx' => '0',<br />
|
| 152 | 'screeny' => '0'<br />
|
| 153 | );<br />
|
| 154 | <br />
|
Derek Allard | 9967ab4 | 2008-02-13 13:14:47 +0000 | [diff] [blame^] | 155 | echo anchor_popup('news/local/123', 'Click Me!', $atts);</code>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 156 |
|
| 157 | <p>Note: The above attributes are the function defaults so you only need to set the ones that are different from what you need.
|
| 158 | If you want the function to use all of its defaults simply pass an empty array in the third parameter:</p>
|
| 159 |
|
Derek Allard | c4e9dc9 | 2007-02-06 19:52:30 +0000 | [diff] [blame] | 160 | <code>echo anchor_popup('news/local/123', 'Click Me!', array());</code>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 161 |
|
| 162 |
|
| 163 | <h2>mailto()</h2>
|
| 164 |
|
| 165 | <p>Creates a standard HTML email link. Usage example:</p>
|
| 166 |
|
| 167 | <code>echo mailto('me@my-site.com', 'Click Here to Contact Me');</code>
|
| 168 |
|
| 169 | <p>As with the <dfn>anchor()</dfn> tab above, you can set attributes using the third parameter.</p>
|
| 170 |
|
| 171 |
|
| 172 | <h2>safe_mailto()</h2>
|
| 173 |
|
| 174 | <p>Identical to the above function except it writes an obfuscated version of the mailto tag using ordinal numbers
|
| 175 | written with JavaScript to help prevent the email address from being harvested by spam bots.</p>
|
| 176 |
|
| 177 |
|
| 178 | <h2>auto_link()</h2>
|
| 179 |
|
| 180 | <p>Automatically turns URLs and email addresses contained in a string into links. Example:</p>
|
| 181 |
|
| 182 | <code>$string = auto_link($string);</code>
|
| 183 |
|
| 184 | <p>The second parameter determines whether URLs and emails are converted or just one or the other. Default behavior is both
|
| 185 | if the parameter is not specified</p>
|
| 186 |
|
| 187 | <p>Converts only URLs:</p>
|
| 188 | <code>$string = auto_link($string, 'url');</code>
|
| 189 |
|
| 190 | <p>Converts only Email addresses:</p>
|
| 191 | <code>$string = auto_link($string, 'email');</code>
|
| 192 |
|
| 193 | </p>The third parameter determines whether links are shown in a new window. The value can be TRUE or FALSE (boolean):</p>
|
| 194 | <code>$string = auto_link($string, 'both', TRUE);</code>
|
| 195 |
|
| 196 |
|
| 197 | <h2>url_title()</h2>
|
| 198 | <p>Takes a string as input and creates a human-friendly URL string. This is useful if, for example, you have a blog
|
| 199 | in which you'd like to use the title of your entries in the URL. Example:</p>
|
| 200 |
|
| 201 | <code>$title = "What's wrong with CSS?";<br />
|
| 202 | <br />
|
| 203 | $url_title = url_title($title);<br />
|
| 204 | <br />
|
| 205 | // Produces: whats-wrong-with-css
|
| 206 | </code>
|
| 207 |
|
| 208 |
|
| 209 | <p>The second parameter determines the word delimiter. By default dashes are used. Options are: <dfn>dash</dfn>, or <dfn>underscore</dfn>:</p>
|
| 210 |
|
| 211 | <code>$title = "What's wrong with CSS?";<br />
|
| 212 | <br />
|
| 213 | $url_title = url_title($title, 'underscore');<br />
|
| 214 | <br />
|
| 215 | // Produces: whats_wrong_with_css
|
| 216 | </code>
|
| 217 |
|
| 218 |
|
| 219 | <h3>prep_url()</h3>
|
| 220 | <p>This function will add <kbd>http://</kbd> in the event it is missing from a URL. Pass the URL string to the function like this:</p>
|
| 221 | <code>
|
Derek Allard | 8788d4b | 2007-08-08 17:04:40 +0000 | [diff] [blame] | 222 | $url = "www.example.com";<br /><br />
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 223 | $url = prep_url($url);</code>
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 | <h2>redirect()</h2>
|
| 229 |
|
| 230 | <p>Does a "header redirect" to the local URI specified. Just like other functions in this helper, this one is designed
|
| 231 | to redirect to a local URL within your site. You will <strong>not</strong> specify the full site URL, but rather simply the URI segments
|
| 232 | to the controller you want to direct to. The function will build the URL based on your config file values.</p>
|
| 233 |
|
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 234 | <p>The second parameter allows you to choose between the "location"
|
Derek Allard | 00aa71c | 2007-10-17 14:45:36 +0000 | [diff] [blame] | 235 | method (default) or the "refresh" method. Location is faster, but on Windows servers it can sometimes be a problem. Example:</p>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 236 |
|
| 237 | <code>if ($logged_in == FALSE)<br />
|
| 238 | {<br />
|
| 239 | redirect('/login/form/', 'refresh');<br />
|
| 240 | }</code>
|
| 241 |
|
| 242 | <p class="important"><strong>Note:</strong> In order for this function to work it must be used before anything is outputted
|
| 243 | to the browser since it utilizes server headers.</p>
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 | </div>
|
| 251 | <!-- END CONTENT -->
|
| 252 |
|
| 253 |
|
| 254 | <div id="footer">
|
| 255 | <p>
|
| 256 | Previous Topic: <a href="typography_helper.html">Typography Helper</a>
|
| 257 | ·
|
| 258 | <a href="#top">Top of Page</a> ·
|
| 259 | <a href="../index.html">User Guide Home</a> ·
|
| 260 | Next Topic: <a href="xml_helper.html">XML Helper</a>
|
Derek Allard | c644128 | 2007-07-04 23:54:32 +0000 | [diff] [blame] | 261 | </p>
|
Derek Jones | 0787043 | 2008-02-13 03:49:26 +0000 | [diff] [blame] | 262 | <p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 263 | </div>
|
| 264 |
|
| 265 | </body>
|
| 266 | </html> |