Laravel 4在默认的getIndex控制器函数上删除/index [英] Laravel 4 remove /index on default getIndex controller function

查看:149
本文介绍了Laravel 4在默认的getIndex控制器函数上删除/index的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在默认的getIndex静态控制器功能上删除/index?

Is it possible to remove /index on default getIndex restful controller function?

控制器的定义路线:

Route::controller('registration', 'RegisterController', array(
  'getIndex' => 'getRegister'
)); 

控制器:

class RegisterController extends UserController {

  public function getIndex()
  {
    // Show the register page
    return View::make('register');
  }
}

例如,在我的login.blade.php中,我有:

For example, in my login.blade.php i have:

{{ HTML::link(URL::route('getRegister'), 'New User?', array('title' => 'Novi korisnik?', 'class'  => 'wideBtn', 'id' => 'userRegisterLink')) }}

返回的结果是这样的链接: http://mydomain.com/registration/index

and returned result is link like this: http://mydomain.com/registration/index

我更喜欢通过URL :: route()获得带有路由名称的链接URL,并且我希望返回的链接如此简单:

I prefer to get link URL over URL::route() with route name, and i want returned link to be simple as this: http://mydomain.com/registration

谢谢

推荐答案

在routes.php文件中:

In your routes.php file:

<?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

和其余的控制器方法仍然映射相同.只要确保它们获得路由即可(或者如果它们需要使用any/post方法).并且它们在控制器方法映射调用之前.不再有 http://example.com/index 链接!

And the rest of the controller methods are still mapped the same. Just make sure they are get routes (or if they need to be any/post methods). And that they are before the controller method mapping call. No more http://example.com/index links anymore!

这篇关于Laravel 4在默认的getIndex控制器函数上删除/index的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆