2014-04-23 67 views
0

我有三個URL:laravel routes.php文件動態URL

localhost:8000/oc/online-marketing/ppc 
localhost:8000/websystems/online-marketing/ppc 
localhost:8000/all/online-marketing/ppc 

,我需要爲每個URL動態設置。

在此之前,我曾經有過這樣的route.php:

Route::get('oc/online-marketing/ppc', function() 
{ 
    $users = User::where('client_id', 1)->get(); 
    return View::make('users')->with('users', $users); 
}); 

但我必須設置動態URL是這樣的:Route::get('{project}/{module}/{submodule}', ...); 其中projectocwebsystems或全部

moduleonline-marketing

submoduleppc

項目名稱ocwebsystemsall可以在表名爲users

我怎樣才能做到這一點通過使用控制器?

回答

0

你可以嘗試一些像foillowing東西,申報Route這樣的:

Route::get('{project}/{module}/{submodule}', array('as' => 'mycontroller.project', 'uses' => '[email protected]')); 

創建Controller

class MyController extends BaseController { 
    public function project($project, $module, $submodule) 
    { 
     //... 
    } 
} 
0

這裏的東西讓你開始與...

在你routes.php文件的文件,你可以有這樣的:

Route::get('/{clientID}', array('uses' => '[email protected]')); 

而在SomeController.php文件:

public function someFunction($clientID) 
{ 
      $users = User::where('client_id', $clientID)->get(); 
      return View::make('users')->with('users', $users); 
} 

欲瞭解更多信息,請參考http://laravel.com/docs/routing#route-parameters