@H_
301_0@这将
显示详细的
错误信息,PagesController 不存在。但在生产环境一定要设置为 false
@H_
301_0@我们可以手工新建控制器,但更快的方式是利用 laravel 提供的
生成器。在命令行当前项目目录中运行:
@H_
301_0@
PHP artisan
@H_
301_0@可以看到laravel提供的
功能。
@H_
301_0@
PHP artisan make:controller PagesController
@H_
301_0@ok,在 app->http->controller 下面
生成了 PagesController.
PHP
PHP;">
PHP namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PagesController extends Controller {
/**
- Display a listing of the resource.
-
- @return Response
*/
public function index()
{
//
}
/**
- Show the form for creating a new resource.
-
- @return Response
*/
public function create()
{
//
}
/**
- Store a newly created resource in storage.
-
- @return Response
*/
public function store()
{
//
}
/**
- Display the specified resource.
-
- @param int $id
- @return Response
*/
public function show($id)
{
//
}
/**
- Show the form for editing the specified resource.
-
- @param int $id
- @return Response
*/
public function edit($id)
{
//
}
/**
- Update the specified resource in storage.
-
- @param int $id
- @return Response
*/
public function update($id)
{
//
}
/**
- Remove the specified resource from storage.
-
- @param int $id
- @return Response
*/
public function destroy($id)
{
//
}
}
@H_
301_0@这样
生成的controller包含了全部所需要的RESTful
方法,我们可以简化一下。
删除生成的PagesController.
PHP,在命令行运行:
@H_
301_0@
PHP artisan make:controller PagesController --plain
@H_
301_0@再看一下
生成的结果
@H_
301_0@
PHP namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PagesController extends Controller {
//
}
@H_
301_0@基本上是一个空的controller,所有的
方法我们需要自己创建。
@H_
301_0@如果你想知道到底有什么参数我们可以在命令行执行,你可以运行下面的命令来查看帮助
@H_
301_0@
PHP artisan help make:controller
@H_
301_0@ok,你可以经常使用help命令来帮助你了解这些参数。
@H_
301_0@在PagesController中建立about
方法。
@H_
301_0@
@H_
301_0@在浏览器冲查看结果,
错误消失,返回简单的信息。
@H_
301_0@
返回视图
@H_
301_0@我们当然希望返回html文档,
修改about
方法的返回:
@H_
301_0@
@H_
301_0@注意:返回的结果是 pages.about ,这表示在 views 子目录中的 pages 子目录中的 about.balde.
PHP 文件。让我们创建 resources\views\pages\about.balde.
PHP 文件
@H_
301_0@
<
Meta charset="UTF-8">
Document
About