Laravel用宁静的嵌套控制器

时间:2012-12-12 15:24:23

标签: laravel php

在我的Laravel项目中,我有以下文件夹结构

application/controllers/products.php

application/controllers/products/categories.php

在我的products.php

class Products_Controller extends Base_Controller {

    public $restful = true;    

    public function get_index()
    {
        $data['title'] = 'Products List';
        return View::make('product.index',$data);
    }    
}

categories.php

class Products_Categories_Controller extends Base_Controller{

    public $restful = true;    

    public function get_index(){

        $data['title'] = "All Categtories";

        return View::make('category.index', $data);
    }    
}

这是我的routes.php

Route::get('products', array('as' => 'products', 'uses' => 'products@index'));
Route::get('products/categories', array('as' => 'categories', 'uses' => 'categories@index'));

当我浏览example.com/products/categories时,我收到了404错误消息。我的routes.php

出了什么问题

1 个答案:

答案 0 :(得分:6)

Route::get('products/categories', array('as' => 'categories', 'uses' => 'products.categories@index'));

请注意'uses' => 'products.categories@index'