Laravel的HelloWorld


さて、前回の記事でLaravelをインストールしました。
流石に何もしないのはマズイので適当にHelloWorldでもしてみます。


laravel/app/controllers 内に TestController.php という名前でファイルを作っておきます。
内容は以下の様な感じで

<?php

class TestController extends BaseController {
	public function getIndex()
	{
		return View::make('helloworld');
	}
}

次は laravel/app/views を開き、 helloworld.php という名前でファイルを作成。
内容は以下の様な感じで

<!doctype html>
<html lang="ja">
<head>
	<meta charset="UTF-8">
	<title>こんにちはせかい</title>
</head>
<body>
	<h1>はろーわーるど</h1>
	<p>こんばんわーるど</p>
</body>
</html>

次は laravel/app/routes.php を編集します。

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

Route::get('/', function()
{
	return View::make('hello');
});

Route::get('helloworld', 'TestController@getIndex'); // 追加

それを保存し http://example.com/helloworld にアクセス。
一応表示されるはずです。
まだ始めたばかりなので慣れていないですが、正直分かりづらいです…
普段ViewとModelを意識せずに書いているせいですね…