2013-10-04 2 views
4

Можно ли удалить/индексировать по умолчанию функцию останова контроллера getIndex?Laravel 4 remove/index по умолчанию функция контроллера getIndex

Определяется маршрут для контроллера:

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 я есть:

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

и возвращается результат Ссылка например: http://mydomain.com/registration/index

Я предпочитаю, чтобы получить ссылку URL через URL :: маршрут() с указанием названия маршрута, и я хочу, вернулся ссылку, чтобы быть простым, как это: http://mydomain.com/registration

Благодаря

ответ

3

В файле routes.php:

<?php 

Route::get('/one', '[email protected]'); 
Route::get('/two', '[email protected]'); 
Route::get('/', '[email protected]'); 

Route::controller('/one', 'OneController'); 
Route::controller('/two', 'TwoController'); 
Route::controller('/', 'HomeController'); 

В любом виде:

{{ action('[email protected]') }} will now return http://example.com/ 
{{ action('[email protected]') }} will now return http://example.com/one 
{{ action('[email protected]') }} will now return http://example.com/two 

И остальных методов контроллера все еще отображаются одинаково. Просто убедитесь, что они получают маршруты (или если они должны быть любыми методами/сообщениями). И это они перед вызовом сопоставления метода контроллера. Не более http://example.com/index ссылки больше!

1

Вы можете использовать как,

Route::resource('registration', 'RegisterController', array('only' => array('index', 'store', 'show', 'update', 'destroy'))); 

Или

Route::resource('registration', 'RegisterController'); 

Тогда вы можете получить доступ к index по GET http://localhost/laravel/registration как,

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

Прочитать документацию here.

Контроллер основные функции будут index, store, show, update, destroy

<?php 

class RegistrationController extends BaseController { 

    /** 
    * Display a listing of the resource. 
    * 
    * @return Response 
    * GET http://localhost/laravel/registration 
    */ 
    public function index() 
    { 
     return View::make('registrations.index'); 
    } 

    /** 
    * Show the form for creating a new resource. 
    * 
    * @return Response 
    */ 
    public function create() 
    { 
     return View::make('registrations.create'); 
    } 

    /** 
    * Store a newly created resource in storage. 
    * 
    * @return Response 
    * POST http://localhost/laravel/registration 
    */ 
    public function store() 
    { 
     // 
    } 

    /** 
    * Display the specified resource. 
    * 
    * @param int $id 
    * @return Response 
    * GET http://localhost/laravel/registration/1 
    */ 
    public function show($id) 
    { 
     return View::make('registrations.show'); 
    } 

    /** 
    * Show the form for editing the specified resource. 
    * 
    * @param int $id 
    * @return Response 
    */ 
    public function edit($id) 
    { 
     return View::make('registrations.edit'); 
    } 

    /** 
    * Update the specified resource in storage. 
    * 
    * @param int $id 
    * @return Response 
    * PUT http://localhost/laravel/registration/1 
    */ 
    public function update($id) 
    { 
     // 
    } 

    /** 
    * Remove the specified resource from storage. 
    * 
    * @param int $id 
    * @return Response 
    * DELETE http://localhost/laravel/registration/1 
    */ 
    public function destroy($id) 
    { 
     // 
    } 

} 

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

  • Нет связанных вопросов^_^