简体   繁体   English

在将变量通过路由传递到Laravel中的控制器时出错

[英]Getting an error in passing a variable through routes to controller in laravel

In app\\routes.php Route::get('author/(:any)',array('as'=>'author','uses'=>'AuthorsController@get_view')); 在app \\ routes.php中Route::get('author/(:any)',array('as'=>'author','uses'=>'AuthorsController@get_view'));

In app\\controllers\\AuthorsController.php 在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));
 }

 }

In views\\authors\\view.blade.php 在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>

In a database there is a table named authors containing columns "id", "name", "bio","created_at","updated_at". 在数据库中,有一个名为authors的表,其中包含列“ id”,“ name”,“ bio”,“ created_at”,“ updated_at”。 Also explain me the exact use of 'as'=>'authors' in the above code 还要向我解释上面代码中'as'=>'authors'的确切用法

Your route is using old style syntax. 您的路线使用的是旧式语法。 In 4.2 use {} in URIs to indicate a variable. 在4.2中,在URI中使用{}表示变量。

Route::get('author/{id}', array('as' => 'author', 'uses' => 'AuthorsController@get_view'));

路线应为:

Route::get('author/{id}', array('as'=>'author', 'uses'=>'AuthorsController@get_view'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM