laravelのResponseオブジェクトのsetContentメソッドについてお聞きしたいことがあります。
php
1<?php 2 3namespace App\Http\Controllers; 4 5use Illuminate\Http\Request; 6use Illuminate\Http\Response; 7 8class HelloController extends Controller{ 9 10 public function index(Request $request,Response $response){ 11 $html = <<<EOF 12 <html> 13 <head> 14 <title>Hello/Index</title> 15 <style> 16 body {font-size:16pt; color:#999;} 17 h1 { font-size:120pt; text-align:right; color:#eee; 18 margin:-50px 0px -120px 0px;} 19 </style> 20 </head> 21 <body> 22 <h1>Hello</h1> 23 <h3>Request</h3> 24 <pre>{$request}</pre> 25 <h3>Response</h3> 26 <pre>{$response}</pre> 27 </body> 28 </html> 29EOF; 30 31$response->setContent($html); 32 return $response; 33 34 } 35}
上記コードにおいて、responseオブジェクトのsetContentメソッドは、引数の値にコンテンツを変更すると、あるのですが、コンテンツとは一体なんなのでしょうか?
試しに、return $responseとしたのですが、中身は空で何も表示はされませんでした。
「$response->setContent($html);return $response;}」こちらを「return $html」のみとし、実行した結果と同じだったのですが、表示する時以外で、setContentメソッドを利用するメリットはありますでしょうか?
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。