将变量传递到视图中

时间:2016-10-22 12:30:40

标签: php laravel-5.2

我是Laravel的新学员,目前我正在玩观点。但是,在我的视图中传递变量之后,我得到了这个异常。基本上它说这条路线不存在。

<ListView x:Name="listaContatti"
    IsItemClickEnabled="True" MaxHeight="200"
    SelectedItem="{Binding ClientiContatti,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
    ItemsSource="{Binding ListaClientiContatti,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <template:ItemTemplateContatti />
        </DataTemplate>
    </ListView.ItemTemplate>
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="Padding" Value="0" />
        </Style>
    </ListView.ItemContainerStyle>
</ListView>

所以这就是我正在做的事情

routes.php文件

NotFoundHttpException in RouteCollection.php line 161:
in RouteCollection.php line 161
at RouteCollection->match(object(Request)) in Router.php line 821
at Router->findRoute(object(Request)) in Router.php line 691
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in    
CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'),    
array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 54

CommentsController.php

Route::get('show_comment/{$id}','CommentsController@showComment');

最后我的观点很简单。

class CommentsController extends Controller
{

public function index()
{

}
/**
 * Show the form for creating a new resource.
 *
 * @return \Illuminate\Http\Response
 */
public function create()
{
    //
    return "inside Create method";
}

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(Request $request)
{
    //
}

/**
 * Display the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function show($id)
{
    return "Show method:" .$id;
}

/**
 * Show the form for editing the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function edit($id)
{
    //
}

/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
  public function update(Request $request, $id)
  {
    //
  }


public function destroy($id)
{
    //

}

public function contact(){
    return view('contacts');
}


public function showComment($id){
    return view('show_comment') -> with('id',$id);
  }

}

我错过了什么?

谢谢,

西奥。

1 个答案:

答案 0 :(得分:1)

正如@Xatenev在评论中所说,它应该只是在路线中删除$以便改变:

Route::get('show_comment/{$id}','CommentsController@showComment');

到:

Route::get('show_comment/{id}','CommentsController@showComment');