-
Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathuri.html
550 lines (523 loc) · 15.1 KB
/
uri.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./../assets/css/combined.css?20170912">
<link rel="shortcut icon" href="./../favicon.ico" />
<script src="https://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
var path = './../';
var class_prefix = "Uri::";
</script>
<script src="./../assets/js/combined.js?20170912"></script>
<title>Uri - Classes - FuelPHP Documentation</title>
</head>
<body>
<div id="container">
<header id="header">
<div class="table">
<div id="cse">
<gcse:searchbox-only newWindow="true"></gcse:searchbox-only>
</div>
<h1>
<a href="https://fuelphp.com"><img height="37px" width="147px" src="./../assets/img/fuel.png" /></a>
<strong>Documentation</strong>
</h1>
</div>
<nav>
<div class="clear"></div>
</nav>
<a href="#" id="toc_handle">table of contents</a>
<div class="clear"></div>
</header>
<div id="main">
<h2>Uri Class</h2>
<p>The Uri class allows you to interact with the URI.</p>
<article>
<h4 class="method" id="method_base">base($include_index = true)</h4>
<p>
The <strong>base</strong> method return the base URL, excluding the index_file when <strong>$include_index</strong>
is set to <em>false</em>.
</p>
<p class="note">
Please note: <strong>$include_index</strong> will be ignored if index_file is not set app/config/config.php
</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$include_index</kbd></th>
<td><pre class="php"><code>true</code></pre></td>
<td>Whether to append the index to the returned url.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string, the base url with optional index file appended</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>echo Uri::base();
// http://localhost/index.php
echo Uri::base(false);
// http://localhost/</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_create">create($uri = null, $variables = array(), $get_variables = array(), $secure = null)</h4>
<p>The <strong>create</strong> method allows you to create a URL with the given URI, including the base URL.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$uri</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>The URL.</td>
</tr>
<tr>
<th><kbd>$variables</kbd></th>
<td><pre class="php"><code>array()</code></pre></td>
<td>The variables for the URL.</td>
</tr>
<tr>
<th><kbd>$get_variables</kbd></th>
<td><pre class="php"><code>array()</code></pre></td>
<td>The query string additions to the URL, its values & keys can use variables from
the $variables array.</td>
</tr>
<tr>
<th><kbd>$secure</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>Set to false to force http, or to true to force https on the created URL</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>echo Uri::create('controller/method');
// returns http://localhost/controller/method
echo Uri::create('controller/:some', array('some' => 'thing', 'and' => 'more'), array('what' => ':and'));
// returns http://localhost/controller/thing?what=more
echo Uri::create('http://www.example.org/:some', array('some' => 'thing', 'and' => 'more'), array('what' => ':and'));
// returns http://www.example.org/thing?what=more
echo Uri::create('http://www.example.org/:some', array('some' => 'thing', 'and' => 'more'), array('what' => ':and'), true);
// returns https://www.example.org/thing?what=more</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_current">current()</h4>
<p>The <strong>current</strong> method allows you to fetch the current URL, including the base URL inside HMVC pattern.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>None</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>// Example URL: http://localhost/module/controller/method
echo Uri::current(); // returns http://localhost/module/controller/method</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_main">main()</h4>
<p>The <strong>main</strong> method allows you to fetch the current URL, including the base URL.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>None</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>// Example URL: http://localhost/controller/method
echo Uri::main(); // returns http://localhost/controller/method</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_segment">segment($segment, $default = null)</h4>
<p>The <strong>segment</strong> method allows you to return the desired segment, or false if it does not exist.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$segment</kbd></th>
<td><i>Required</i></td>
<td>The segment number.</td>
</tr>
<tr>
<th><kbd>$default</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>The default?</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>// Example URL: http://localhost/controller/method/param1/param2
echo Uri::segment(3); // returns param1</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_segments">segments()</h4>
<p>The <strong>segments</strong> method allows you to fetch the current URI segments in an array.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>None</td>
</tr>
<tr>
<th>Returns</th>
<td>array</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>// Example URL: http://localhost/controller/method
echo Uri::segments(); // returns array(0 => 'controller', 1 => 'method')</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_segment_replace">segment_replace($url, $secure = null)</h4>
<p>The <strong>segment_replace</strong> method allows you to replace wildcards in a given url by the current URI segment in that position.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$url</kbd></th>
<td><i>Required</i></td>
<td>The url containing wildcards. A wildcard is defined by a * character.</td>
</tr>
<tr>
<th><kbd>$secure</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>If false, the url returned will use HTTP, if true, it will use HTTPS.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Throws</th>
<td>OutOfBoundsException, if a wildcard is at a segment location for which no value exists.</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>// Example: Current URL = http://localhost/one/two, with segments 'one' and 'two'
// returns http://localhost/one/two/three
echo Uri::segment_replace('http://localhost/*/*/three');
// throws an exception, as there is no third segment available
echo Uri::segment_replace('http://localhost/this/that/*/other');
// returns https://localhost/one/two/three
echo Uri::segment_replace('http://localhost/*/*/three', true);</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_update_query_string">update_query_string($vars = array(), $uri = null, $secure = null)</h4>
<p>
The <strong>update_query_string</strong> method allows you to update the query string in the current or passed URI.
</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$vars</kbd></th>
<td><pre class="php"><code>array()</code></pre></td>
<td>An assoc array of query variables, or a string containing the variable name.</td>
</tr>
<tr>
<th><kbd>$uri</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>
The url to use. If not given, the current url will be used. If $vars is a string, this will contain
the variables value (which implies you can't pass a custom uri in that case!).
</td>
</tr>
<tr>
<th><kbd>$secure</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>If false, the url returned will use HTTP, if true, it will use HTTPS.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>// Example: Current URL = http://localhost/test?one=1&two=2
// returns http://localhost/test?one=1&two=2&three=3
echo Uri::update_query_string(array('three' => 3));
// returns http://localhost/test?one=1&two=3
echo Uri::update_query_string(array('two' => 3));
// returns http://localhost/controller?four=4
echo Uri::update_query_string(array('four' => 4), 'http://localhost/controller');
// returns https://localhost/test?one=1&two=2&three=3
echo Uri::update_query_string('three', 3, true);</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_to_assoc">to_assoc($start = 1)</h4>
<p>The <strong>to_assoc</strong> method takes the segments array and turns it into an associative array if the number of segments is even. If the number of segments is odd, the last array key will have a value of <code>null</code>.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$start</kbd></th>
<td><pre class="php"><code>1</code></pre></td>
<td>The segment number to start with. This allows you to strip leading segments.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>array</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>// Uri is /welcome/index/page/4
$arr = Uri::to_assoc();
/*
Result:
array(
'welcome' => 'index',
'page' => 4,
);
*/
// Uri is /welcome
$arr = Uri::to_assoc();
/*
Result:
array(
'welcome' => null,
);
*/</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_string">string()</h4>
<p>The <strong>string</strong> method allows you to fetch the current URI.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>None</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>// Example URL: http://localhost/controller/method
echo Uri::string(); // returns controller/method</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_build_query_string">build_query_string($values ...)</h4>
<p>
The <strong>build_query_string</strong> method allows you to generate a query string from one or more passed assoc array or string values.
You can pass in Input::get() to construct an updated query string from the existing one. If you pass a string, it will be assumed to be a
switch, and will be converted to "string=1".
</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$values</kbd></th>
<td><i>Required</i></td>
<td>One or more associative array's or string values</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>// returns "varA=varA&varB=1&varC=varC"
echo Uri::build_query_string(array('varA' => 'varA'), 'varB', array('varC' => 'varC'));</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
</div>
<footer>
<p>
© FuelPHP Development Team 2010-2025 - <a href="https://fuelphp.com">FuelPHP</a> is released under the MIT license.
</p>
</footer>
</div>
</body>
</html>