forked from NEKOGET/FuelPHP_docs_jp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.html
714 lines (670 loc) · 21.6 KB
/
view.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
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
<!doctype html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./../assets/css/combined.css">
<link rel="shortcut icon" href="./../favicon.ico" />
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
var path = './../';
var class_prefix = "View::";
</script>
<script src="./../assets/js/combined.js"></script>
<title>View - クラス - FuelPHP ドキュメント</title>
</head>
<body>
<div id="container">
<header id="header">
<div class="table">
<h1>
<a href="http://fuelphp.com"><img height="37px" width="147px" src="./../assets/img/fuel.png" /></a>
<strong>Documentation</strong>
</h1>
<form id="google_search">
<p>
<span id="search_clear"> </span>
<input type="submit" name="search_submit" id="search_submit" value="検索" />
<input type="text" value="" id="search_input" name="search_input" />
</p>
</form>
</div>
<nav>
<div class="clear"></div>
</nav>
<a href="#" id="toc_handle">目次</a>
<div class="clear"></div>
</header>
<div id="cse">
<div id="cse_point"></div>
<div id="cse_content"></div>
</div>
<div id="main">
<h2>View クラス</h2>
<p>
View クラスは、"ビュー" と呼ばれる PHP コードが埋め込まれた HTML ページのラッパーとして機能します。
変数は view オブジェクトに割り当てられ、ビューの中でローカル参照できます。
</p>
<p>
<a href="../general/views.html">ビューを使用する方法はこちらを参照ください。</a>
</p>
<article>
<h4 class="method" id="method_construct">__construct($file = null, $data = null, $filter = null)</h4>
<table class="method">
<tbody>
<tr>
<th>静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$file</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td class="description">ビューファイル名、指定されていない場合は後で <em>set_filename</em> を利用して指定するか <em>render</em> の中で指定しないといけません。ビューファイルは、<em>app/views</em> ディレクトリからの相対パスにする必要があります。</td>
</tr>
<tr>
<th><kbd>$data</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td class="description">値の配列</td>
</tr>
<tr>
<th><kbd>$filter</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td class="description">自動エンコーディングを行うかを <em>true</em> か <em>false</em> でセットします。メインの設定 (app/config/config.php) がデフォルトとなります。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>新しい <em>View</em> オブジェクト</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>$view = new View('path/to/view', array(
'menu' => $menu,
'articles' => $articles,
'footer_links' => $footer_links,
));</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_forge">forge($file = null, $data = null, $filter = null)</h4>
<p><strong>forge</strong> メソッドは、新しい View オブジェクトを返します。</p>
<table class="method">
<tbody>
<tr>
<th>静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$file</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td class="description">ビューファイル名、指定されていない場合は後で <em>set_filename</em> を利用して指定するか <em>render</em> の中で指定しないといけません。ビューファイルは、<em>app/views</em> ディレクトリからの相対パスにする必要があり <strong>.php</strong> ファイル拡張子を持ちません。</td>
</tr>
<tr>
<th><kbd>$data</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td class="description">値の配列</td>
</tr>
<tr>
<th><kbd>$filter</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td class="description">自動エンコーディングを行うかを <em>true</em> か <em>false</em> でセットします。メインの設定 (app/config/config.php) がデフォルトとなります。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>新しい <em>View</em> オブジェクト</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// APPPATH の View オブジェクトを作成する
$view = View::forge('path/to/view', array(
'menu' => $menu,
'articles' => $articles,
'footer_links' => $footer_links,
));</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_auto_encode">auto_filter($filter = true)</h4>
<p><strong>auto_filter</strong> メソッドは、View インスタンス上でデータをエンコードするかどうかをセットします。</p>
<table class="method">
<tbody>
<tr>
<th>静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$filter</kbd></th>
<td><pre class="php"><code>true</code></pre></td>
<td class="description">View インスタンス上でデータをエンコードするかどうか</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>現在の View オブジェクト</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>$view = View::forge('path/to/view', array(
'menu' => $menu,
'articles' => $articles,
'footer_links' => $footer_links,
));
$view->auto_filter();
// または、false にセットする
$view->auto_filter(false);
// または、チェーンして
$view = View::forge('path/to/view', array(
'menu' => $menu,
'articles' => $articles,
'footer_links' => $footer_links,
))->auto_filter();</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_set_filename">set_filename($file)</h4>
<p><strong>set_filename</strong> メソッドは、ビューファイル名のセットや変更を行うことができます。</p>
<table class="method">
<tbody>
<tr>
<th>静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$file</kbd></th>
<td><em>必須</em></td>
<td class="description">ビューファイル名。ビューファイルは、<em>app/views</em> ディレクトリからの相対パスにする必要があり <strong>.php</strong> ファイル拡張子を持ちません。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>現在の View オブジェクト</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>$view = new View();
$view->set_filename('path/to/view');</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_get">get($key = null, $default = null)</h4>
<p><strong>get</strong> メソッドは、ビューにセットする 1 つまたは全ての変数を取得します。</p>
<table class="method">
<tbody>
<tr>
<th>静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$key</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td class="description">変数名</td>
</tr>
<tr>
<th><kbd>$default</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td class="description">変数が存在しなかったときに返されるデフォルト値</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>mixed</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// view を作成し、データをセットする
$view = new View;
$view->set(array('field1' => 'value1', 'field2' => 'value2');
// 1 つの値を取得
$field1 = $view->get('field1');
// 1 つの値を取得、もしフィールドが存在しなかった場合はデフォルトがセットされる
$field3 = $view->get('field3', 'value3');
// 全ての値を取得
$fields = $view->get();</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_set">set($key, $value = null, $filter = null)</h4>
<p><strong>set</strong> メソッドは、ビューに変数を割り当てます。</p>
<table class="method">
<tbody>
<tr>
<th>静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$key</kbd></th>
<td><em>必須</em></td>
<td class="description">変数名または変数の配列</td>
</tr>
<tr>
<th><kbd>$value</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td class="description">値</td>
</tr>
<tr>
<th><kbd>$filter</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td class="description">エンコーディングを行うかを <em>true</em> か <em>false</em> でセットします。メインの自動エンコーディング設定がデフォルトとなります。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>現在の View オブジェクト</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>$view = new View;
$view->set('users', $users, false);
// または配列をセットする
$view->set(array(
'users' => $users,
'articles' => $articles,
), null, true);
// 出力時のエンコーディングが有効なとき、
// HTML / Javascript を渡すには最後のパラメータを false にセットする必要があります。
$view->set('example', '<h1>Heading</h1>', false);</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_set_safe">set_safe($key, $value = null)</h4>
<p>デフォルトで出力時に変数のエンコーディングを行わないこと以外は、<code>set()</code> と同じです。</p>
<table class="method">
<tbody>
<tr>
<th>静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$key</kbd></th>
<td><em>必須</em></td>
<td class="description">変数名または変数の配列</td>
</tr>
<tr>
<th><kbd>$value</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td class="description">値</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>現在の View オブジェクト</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>$view = new View;
$view->set_safe('users', $users);
// または、配列をセットする
$view->set_safe(array(
'users' => $users,
'articles' => $articles,
), null);</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_set_global">set_global($key, $value = null, $filter = null)</h4>
<p><strong>set_global</strong> メソッドは、全てのビューで変数を利用できるようにセットします。</p>
<table class="method">
<tbody>
<tr>
<th>静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$key</kbd></th>
<td><em>必須</em></td>
<td class="description">変数名または変数の配列</td>
</tr>
<tr>
<th><kbd>$value</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td class="description">値</td>
</tr>
<tr>
<th><kbd>$filter</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td class="description">エンコーディングを行うかを <em>true</em> か <em>false</em> でセットします。メインの自動エンコーディング設定がデフォルトとなります。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td><em>Void</em></td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>View::set_global('users', $users, false);
// または、配列をセットする
View::set_global(array(
'users' => $users,
'articles' => $articles,
), null, true);</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_bind">bind($key, $value = null)</h4>
<p>
参照によって値を割り当てます。バインディングの利点は、再設定することなく値を変更できることです。
それらが値を持つ前に、変数をバインドすることも可能です。
割り当てられた値は、ビューファイル内の変数として利用することができます。
</p>
<p class="note">注意してください: これらは出力のエンコーディングでクリーニングされないので、安全ではないと見なすべきです。</p>
<table class="method">
<tbody>
<tr>
<th>静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$key</kbd></th>
<td><em>必須</em></td>
<td class="description">変数名または変数の配列</td>
</tr>
<tr>
<th><kbd>$value</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td class="description">値</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>現在の View オブジェクト</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>$view = new View;
$view->bind('users', $users, false);
// または、配列をセットする
$view->bind(array(
'users' => $users,
'articles' => $articles,
), null, true);</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_bind_global">bind_global($key, $value = null)</h4>
<p><strong>bind_global</strong> メソッドは、全てのビューで参照によるグローバル変数を利用できるように割り当てます。</p>
<p class="note">注意してください: これらは出力のエンコーディングでクリーニングされないので、安全ではないと見なすべきです。</p>
<table class="method">
<tbody>
<tr>
<th>静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$key</kbd></th>
<td><em>必須</em></td>
<td class="description">変数名</td>
</tr>
<tr>
<th><kbd>$value</kbd></th>
<td><em>必須</em></td>
<td class="description">値</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td><em>Void</em></td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>View::bind_global('users', $users);</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_render">render($file = null)</h4>
<p>
<strong>render</strong> メソッドは、view オブジェクトを文字列へレンダリングします。
グローバルとローカルのデータはマージされて、ビューファイル内のローカル変数として展開されます。
</p>
<table class="method">
<tbody>
<tr>
<th>静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>型</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$file</kbd></th>
<td><em>string</em></td>
<td><pre class="php"><code>null</code></pre></td>
<td class="description">拡張子なしのビューファイル名</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td><strong>レンダリングされたビューファイル</strong></td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>$html = View::forge()->render('path/to/view');
// または
$html = View::forge('path/to/view')->render();
// または
$html = View::forge()->set_filename('path/to/view')->render();</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<h3 id="procedural_helpers">手続き型ヘルパー</h3>
<article>
<h4 id="function_render" class="method" data-class="">render($view, $data = array(), $auto_filter = null)</h4>
<p><strong>render</strong> 関数は、<a href="#method_render">View::render</a> の別名です。</p>
<table class="method">
<tbody>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>型</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$view</kbd></th>
<td><em>string</em></td>
<td><em>必須</em></td>
<td class="description">拡張子なしのビューファイル名</td>
</tr>
<tr>
<th><kbd>$data</kbd></th>
<td><em>array</em></td>
<td><pre class="php"><code>array()</code></pre></td>
<td class="description">view へ渡すデータの配列</td>
</tr>
<tr>
<th><kbd>$auto_filter</kbd></th>
<td><em>bool</em></td>
<td><pre class="php"><code>null</code></pre></td>
<td class="description">データをフィルタするかしないか</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td><strong>string 。<a href="#method_render">View::render</a> の結果</strong></td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>$html = render('path/to/view', $data_array);</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
</div>
<footer>
<p>
© FuelPHP Development Team 2010-2016 - <a href="http://fuelphp.com">FuelPHP</a> is released under the MIT license.
[ <a href="https://github.com/fuel/docs/commits/1.8/develop/classes/view.html">原文コミット履歴</a> | <a href="https://github.com/NEKOGET/FuelPHP_docs_jp/commits/1.8/develop_japanese/classes/view.html">翻訳コミット履歴</a> | <a href="https://github.com/NEKOGET/FuelPHP_docs_jp/blob/1.8/develop_japanese/classes/view.html">GitHubで修正</a> ]
</p>
</footer>
</div>
</body>
</html>