【发布时间】:2015-04-01 14:03:08
【问题描述】:
在 app\routes.php 中
Route::get('author/(:any)',array('as'=>'author','uses'=>'AuthorsController@get_view'));
在 app\controllers\AuthorsController.php 中
<?php
class AuthorsController extends BaseController {
public $restful=true;
public function get_view($id){
return View::make('authors.view')
->with('title','Author View Page')
->with('author',Author::find($id));
}
}
在views\authors\view.blade.php中
<!DOCTYPE html>
<html>
<head> <title> {{ $title }}</title> </head>
<body>
<h1> {{$author->name}}</h1>
<p> {{ $author->bio}} </p>
<p><small>{{$author->updated_at}} <small></p>
</body>
</html>
在数据库中有一个名为 authors 的表,其中包含“id”、“name”、“bio”、“created_at”、“updated_at”列。 还要解释一下上面代码中'as'=>'authors'的确切用法
【问题讨论】:
-
你在使用 Laravel 3 吗?
-
我使用的是 laravel 4.2
-
你确定吗?在 Laravel 4.2 中,您的路线如下所示:
Route::get('author/{id}', ...
标签: php mysql laravel laravel-routing