控制器中的路由和功能出错

时间:2014-03-08 16:16:03

标签: laravel-4

在app / routes.php文件中,我添加" Route :: resource(' cat',' CatController');"

这是一个CatController代码:

<?php

class CatController extends \BaseController {

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
         return 'This is cat controller index.';

    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create()
    {
        //
        return 'This is a form to create new cat !';
    }

    /**
     * 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)
    {
        //
        return 'Show the cat number:' . $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)
    {
        //
    }

}

当我调用网址:http://www.domain.com/laravel/public/cat/edit时,它会返回:

显示猫号:编辑

为什么它会返回节目功能内容?!

1 个答案:

答案 0 :(得分:0)

edit($id)的网址格式为/resource/{id}/edit - 您只是使用/resource/edit,其被解释为/resource/{id},指向show($id)方法。< / p>