2014-03-19 27 views
0

過去兩天我一直在爲這個問題而苦苦掙扎。最後決定後我的問題:Laravel 4正確地命名了路由路由,但沒有顯示視圖的內容

routes.php文件

Route::get('authors/newAuthors', array('as'=>'new', 'uses'=> '[email protected]')); 

控制器(authors.php)

public function newAuthors(){ 
    $value = View::make('authors.newAuthors') 
      ->with('title', 'authors Adding Page'); 
    return $value; 
} 

index.blade.php(在該視圖中,我有一個鏈接,命名路線「新作者」)應顯示點擊(newAuthors.blade.php後

@extends('layouts.master') 

@section('content') 
<h2>Authors page from index blade php</h2> 
    <ul> 

    @foreach($authors as $author) 
     <li>{{ HTML::linkRoute('author', $author->name, `array($author['id'])) }}</li>` 
    @endforeach 

    </ul> 
    {{ HTML::linkRoute('new', 'New Authors') }} 
@stop 

視圖)

@extends('layouts.master') 

@section('content') 

<h2>Add New Authors</h2> 

@stop 

當我點擊鏈接(「新作者」)上,在URL它表明我,這是路由到正確的路徑:

http://localhost:8000/authors/newAuthors 

但它不顯示任何比賽該視圖文件(newAuthors.blade.php)

回答

0

最終,我解決了這個問題。我發現了一個類似的問題,但不完全是在這裏

Routed Problem

我所做的一切轉移我的,我是在什麼上面有有問題的這個特殊的途徑,比它開始顯示我的右視圖。沒有什麼破碎的。我不知道它是如何發生的,但我有以下路線,現在起作用:

Route::get('authors/newAuthors', array('as'=>'new', 'uses'=> '[email protected]')); 

Route::get('authors', array('as' => 'authors', 'uses' => '[email protected]')); 
Route::get('authors/{id}', array('as'=>'author', 'uses'=> '[email protected]')); 

即使我沒有任何完全匹配的URI。無論如何,我寫的任何思考未來遊客可能會發現它的幫助,並沒有像我掙扎了兩天:(

0

你的銼刀刀片是:「index.blade.php」

,所以你需要點您的佈局到本文件:(如果該指數是一個子文件夾中使用的子文件夾/索引)

$value = View::make('index') 
     ->with('title', 'authors Adding Page'); 

然後在您的route.php添加路由:

Route::get('authors/newauthors/', array('as' => 'newAuthors', 'uses' => '[email protected]')); 

用它在你看來

{{link_to_route('newAuthors', 'New Authors', $parameters = array(), $attributes = array())}} 
+0

link_to_route()...方法在laravel中不再存在4.按照鏈接::: http://stackoverflow.com/questions/16845540/laravel-method-link-to-route-does - 不存在 – score

+0

你是對的SHANKAR。這只是命名路線的一個例子。 – JulianoMartins