2014-01-06 2 views
6

Я пытаюсь получить доступ к моему URL адресу:Laravel контроллер RESTful маршрутизации

www.mysite.com/user/dash/sales

у меня в каталоге контроллеров, DashboardController. PHP файл:

<?php 

class DashboardController extends BaseController { 

    public function __construct() { 

     $this->beforeFilter('auth'); 

    } 

    /** 
    * Supplier's dashboard screen 
    * 
    */ 
    public function getSupplier() 
    { 
     $this->layout->content = View::make('user.dashboard.supplier'); 
    } 

    /** 
    * Sales dashboard screen 
    * 
    */ 
    public function getSales() 
    { 
     $this->layout->content = View::make('user.dashboard.sales'); 
    } 

    /** 
    * Admin's dashboard screen 
    * 
    */ 
    public function getAdmin() 
    { 
     $this->layout->content = View::make('user.dashboard.admin'); 
    } 

} 

Я пробовал все следующие возможности в моем файле routes.php не повезло:

Route::any('user/dash/(:any)', array('uses' => 'DashboardController')); 

Route::controller('user/dash', 'DashboardController'); 

Route::group(array('prefix' => 'user', 'before' => 'auth'), function() 
{ 
    Route::controller('dash', 'DashboardController'); 
}); 

Есть ли у кого-нибудь другие предложения? Я не совсем уверен, как сделать этот успешный маршрут. Сообщение об ошибке, которое я получаю со всеми этими маршрутами, таково:

Метод контроллера не найден.

ответ

3

Ok после того, как много больше копаться вокруг и чтение нагрузок статей, есть это правило называется «первым пришел, первым обслужен»:

<?php 

/* 
|-------------------------------------------------------------------------- 
| Application Routes 
|-------------------------------------------------------------------------- 
| 
| Here is where you can register all of the routes for an application. 
| It's a breeze. Simply tell Laravel the URIs it should respond to 
| and give it the Closure to execute when that URI is requested. 
| 
*/ 

/** RESTful Controllers **/ 
Route::controller('user/dash', 'DashboardController'); 
Route::controller('user', 'UserController'); 
Route::controller('product', 'ProductController'); 

Route::group(array('prefix' => 'dash', 'before' => 'auth'), function() 
{ 
    Route::controller('product', 'Dash_ProductController'); 
    Route::controller('user', 'Dash_UserController'); 
}); 

/** Home/Fallback Controller **/ 
Route::controller('/', 'HomeController'); 

Итак, поэтому если у вас есть маршрут, ведущий к пользователю, но затем захотите углубиться, вы должны поместить самый глубокий FIRST в свой файл route.php!

Фантастическая статья следующего содержания: http://laravel.io/topic/30/routes-first-in-first-out

Ответил: user3130415

+0

Upvoted хотя ссылка сломана – kJamesy

+0

@kJamesy Вот ссылка из архива, http://web.archive.org/web/20130912011338/ http://laravel.io/topic/30/routes-first-in-first-out – Stranger

Смежные вопросы