routing - Laravel RESTful Controller 路由

标签 routing laravel-4

我正在尝试访问我的 URL:

www.mysite.com/user/dash/sales



我在我的 Controller 目录中有一个 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');
});

有没有人有其他建议?我不太确定如何使这条路线成功。我收到的所有这些路由的错误消息是:

Controller method not found.

最佳答案

好吧,经过大量挖掘和阅读大量文章后,有一条规则称为“先进先出”:

<?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 放在 routes.php 文件中!

精彩文章阅读:http://laravel.io/topic/30/routes-first-in-first-out

回答者:user3130415

关于routing - Laravel RESTful Controller 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20956469/

相关文章:

google-app-engine - 第三方路由器和静态文件

json - Laravel返回json或view

php - Laravel strftime 与 Homestead 无法正常工作

php - 不允许序列化 'Closure' - laravel

c# - 如何处理这个路由?

routing - 带参数的 Laravel 4 命名空间 Controller 路由

docker - 将 Docker 容器连接到家庭网络

php - Laravel 即时更新电子邮件配置

Laravel 4 SQL 日志/控制台

.net - .net 中带点的语义网址