是否可以在默认的 getIndex Restful Controller 功能上删除/index ?
Controller 的定义路由:
Route::controller('registration', 'RegisterController', array(
'getIndex' => 'getRegister'
));
Controller :
class RegisterController extends UserController {
public function getIndex()
{
// Show the register page
return View::make('register');
}
}
例如,在我的 login.blade.php 我有:
{{ HTML::link(URL::route('getRegister'), 'New User?', array('title' => 'Novi korisnik?', 'class' => 'wideBtn', 'id' => 'userRegisterLink')) }}
返回的结果是这样的链接:http://mydomain.com/registration/index
我更喜欢使用路由名称通过 URL::route() 获取链接 URL,并且我希望返回的链接简单如下:http://mydomain.com/registration
谢谢
最佳答案
在你的 routes.php 文件中:
<?php
Route::get('/one', 'OneController@getIndex');
Route::get('/two', 'TwoController@getIndex');
Route::get('/', 'HomeController@getIndex');
Route::controller('/one', 'OneController');
Route::controller('/two', 'TwoController');
Route::controller('/', 'HomeController');
在任何情况下:
{{ action('HomeController@getIndex') }} will now return http://example.com/
{{ action('OneController@getIndex') }} will now return http://example.com/one
{{ action('TwoController@getIndex') }} will now return http://example.com/two
其余的 Controller 方法仍然映射相同。只需确保它们是 get 路由(或者它们是否需要是 any/post 方法)。并且它们在 Controller 方法映射调用之前。没有了 http://example.com/index链接了!
关于Laravel 4 在默认的 getIndex Controller 函数上删除/index,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19190389/