2013-10-22 101 views
-1

我剛剛開始學習laravel。並從nettuts +(網址縮寫)中找到一個小樣本項目。它運作良好,但只有我面對的問題是(:任何)路線不起作用。 這裏有三條路線,我有檔案。laravel 3 - (:any)route not working

Route::get('/', function() 
{ 
    return View::make('home.index'); 
}); 

Route::post('/', function() 
{ 
    $url = Input::get('url'); 

    // Validate the url 
    $v = Url::validate(array('url' => $url)); 
    if ($v !== true) { 
     return Redirect::to('/')->with_errors($v->errors); 
    } 

    // If the url is already in the table, return it 
    $record = Url::where_url($url)->first(); 
    if ($record) { 
     return View::make('home.result') 
       ->with('shortened', $record->shortened); 
    } 

    // Otherwise, add a new row, and return the shortened url 
    $row = Url::create(array(
     'url' => $url, 
     'shortened' => Url::get_unique_short_url() 
    )); 

    // Create a results view, and present the short url to the user 
    if ($row) { 
     return View::make('home.result')->with('shortened', $row->shortened); 
    } 
}); 

Route::get('(:any)', function($shortened) 
{ 
    // query the DB for the row with that short url 
    $row = Url::where_shortened($shortened)->first(); 

    // if not found, redirect to home page 
    if (is_null($row)) return Redirect::to('/'); 

    // Otherwise, fetch the URL, and redirect. 
    return Redirect::to($row->url); 
}); 

前兩條路線工作正常,但第三條路線從未激活。它只適用於如果我在url中用index.php調用它。像/index.php/abc一樣,它也適用於/ abc。而且,我也從應用程序配置文件中刪除了index.php設置。

你能幫我解決嗎?

回答

0

變化從'(:any)'

Route::get('(:any)', function($shortened){ //... }); 

路線聲明('/(:any)'

Route::get('/(:any)', function($shortened){ //... });