Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel Restful资源控制器路由getShow()_Php_Laravel_Laravel 4 - Fatal编程技术网

Php Laravel Restful资源控制器路由getShow()

Php Laravel Restful资源控制器路由getShow(),php,laravel,laravel-4,Php,Laravel,Laravel 4,我很难让这里定义的Restful路由()正常工作 我可以让创建表单和索引(全部视图)正常工作,但我无法让单个项目的链接正常工作。getShow 我已经将我的路由定义为restful,因此它应该使用my routes.php中的自动路由: // People Route::controller('people', 'PeopleController'); 这是我的控制器PeopleController.php: <?php class PeopleController extends Ba

我很难让这里定义的Restful路由()正常工作

我可以让创建表单和索引(全部视图)正常工作,但我无法让单个项目的链接正常工作。getShow

我已经将我的路由定义为restful,因此它应该使用my routes.php中的自动路由:

// People
Route::controller('people', 'PeopleController');
这是我的控制器PeopleController.php:

<?php
class PeopleController extends BaseController {

    public $restful = true;

    public function getIndex()
    {   


        return View::make('people.index')
            ->with('people', $people);          
    }

    public function getShow($id)
    {   
    return 'success! it finally worked!';   
    }


    public function getCreate()
    {
        return View::make('people.create');
    }

    public function postStore()
    {

            return Redirect::to('people')
                ->with('success', 'Person added successfully');
     }

}

您需要将链接更改为

<a href="{{ URL::to('people/show/' . $people->people_id) }}">
但我怀疑这是你想要的


我敢打赌,如上所述,只要更改链接就可以解决您的问题:)

我会使用资源路由:
控制器是RESTful的,并且更容易理解。我使用控制器路由的唯一地方是用于处理任意项的控制器,如页面控制器。通过这种方式,您可以使用一致的访问页面的方式。

请尝试people/show/1,因为getIndex方法声明中没有参数。我将使用
{url('people/show',$people->people\u id)}
,您可以将参数传递给函数,而无需字符串连接。
@extends('master')

@section('title')
@parent
:: Home
@stop

@section('content')
<p>it finally worked!</p>

@stop
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
…\vendor\laravel\framework\src\Illuminate\Routing\Controllers\Controller.php290
Illuminate\Routing\Controllers\Controller missingMethod
<#unknown>0
call_user_func_array
…\vendor\laravel\framework\src\Illuminate\Routing\Controllers\Controller.php138
Illuminate\Routing\Controllers\Controller callMethod
…\vendor\laravel\framework\src\Illuminate\Routing\Controllers\Controller.php115
Illuminate\Routing\Controllers\Controller callAction
…\bootstrap\compiled.php9980
Illuminate\Routing\{closure}
<#unknown>0
call_user_func_array
…\bootstrap\compiled.php16626
Illuminate\Routing\Route callCallable
…\bootstrap\compiled.php16605
Illuminate\Routing\Route run
…\bootstrap\compiled.php10000
Illuminate\Routing\Router dispatch
…\bootstrap\compiled.php1010
Illuminate\Foundation\Application dispatch
…\bootstrap\compiled.php993
Illuminate\Foundation\Application run
…\public\index.php49
<a href="{{ URL::to('people/show/' . $people->people_id) }}">
function getIndex($id=null){
    if($id==null){
       $people = People::all();           
     } else {
       $people = People::find($id);
     }
    return View::make('people.index')
    ->with('people', $people);  
  }