2013-10-22 100 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){ //... });