Laravel: 将索引重定向到另一个索引。从路由或控制器调用路由?
Laravel: Redirecting index to another index. Call a route from a route or controller?
我定义了一堆路由
# Programs Management
Route::resource('programs', 'AdminProgramController');
Route::resource('scheduled_programs', 'AdminScheduledProgramController');
Route::resource('attendees', 'AdminAttendeeController');
# User Management
Route::get('users/{user}/show', 'AdminUsersController@getShow');
Route::get('users/{user}/edit', 'AdminUsersController@getEdit');
Route::post('users/{user}/edit', 'AdminUsersController@postEdit');
Route::get('users/{user}/delete', 'AdminUsersController@getDelete');
Route::post('users/{user}/delete', 'AdminUsersController@postDelete');
Route::controller('users', 'AdminUsersController');
# User Role Management
Route::get('roles/{role}/show', 'AdminRolesController@getShow');
Route::get('roles/{role}/edit', 'AdminRolesController@getEdit');
Route::post('roles/{role}/edit', 'AdminRolesController@postEdit');
Route::get('roles/{role}/delete', 'AdminRolesController@getDelete');
Route::post('roles/{role}/delete', 'AdminRolesController@postDelete');
Route::controller('roles', 'AdminRolesController');
# Admin Dashboard
Route::controller('/', 'AdminDashboardController');
对我来说看起来漂亮整洁,但我知道我的 /
路线现在只会指向 scheduled_programs
。稍后我可能会更改它以指向另一条路线,但它可能永远不需要它自己的视图。
class AdminDashboardController extends AdminController {
/**
* Admin dashboard
*
*/
public function getIndex()
{
return View::make('admin/dashboard');
}
class AdminScheduledProgramController extends \BaseController {
/**
* Display a listing of scheduled_programs
*
* @return Response
*/
public function index()
{
$programs = ScheduledProgram::all();
return View::make('admin/scheduled_programs/index', compact('programs'));
}
我是框架的新手,在路由或控制器中更改路由在哪里有意义?我怎么做? IE 从路由或控制器调用路由?我认为将索引代码从一个复制到另一个是不好的形式。如果我错了请纠正我。
哎呀,答案很明显,只是 return Redirect::route 到另一条路线。
class AdminDashboardController extends AdminController {
/**
* Admin dashboard
*
*/
public function getIndex()
{
return Redirect::route('admin.scheduled_programs.index');
}
}
我定义了一堆路由
# Programs Management
Route::resource('programs', 'AdminProgramController');
Route::resource('scheduled_programs', 'AdminScheduledProgramController');
Route::resource('attendees', 'AdminAttendeeController');
# User Management
Route::get('users/{user}/show', 'AdminUsersController@getShow');
Route::get('users/{user}/edit', 'AdminUsersController@getEdit');
Route::post('users/{user}/edit', 'AdminUsersController@postEdit');
Route::get('users/{user}/delete', 'AdminUsersController@getDelete');
Route::post('users/{user}/delete', 'AdminUsersController@postDelete');
Route::controller('users', 'AdminUsersController');
# User Role Management
Route::get('roles/{role}/show', 'AdminRolesController@getShow');
Route::get('roles/{role}/edit', 'AdminRolesController@getEdit');
Route::post('roles/{role}/edit', 'AdminRolesController@postEdit');
Route::get('roles/{role}/delete', 'AdminRolesController@getDelete');
Route::post('roles/{role}/delete', 'AdminRolesController@postDelete');
Route::controller('roles', 'AdminRolesController');
# Admin Dashboard
Route::controller('/', 'AdminDashboardController');
对我来说看起来漂亮整洁,但我知道我的 /
路线现在只会指向 scheduled_programs
。稍后我可能会更改它以指向另一条路线,但它可能永远不需要它自己的视图。
class AdminDashboardController extends AdminController {
/**
* Admin dashboard
*
*/
public function getIndex()
{
return View::make('admin/dashboard');
}
class AdminScheduledProgramController extends \BaseController {
/**
* Display a listing of scheduled_programs
*
* @return Response
*/
public function index()
{
$programs = ScheduledProgram::all();
return View::make('admin/scheduled_programs/index', compact('programs'));
}
我是框架的新手,在路由或控制器中更改路由在哪里有意义?我怎么做? IE 从路由或控制器调用路由?我认为将索引代码从一个复制到另一个是不好的形式。如果我错了请纠正我。
哎呀,答案很明显,只是 return Redirect::route 到另一条路线。
class AdminDashboardController extends AdminController {
/**
* Admin dashboard
*
*/
public function getIndex()
{
return Redirect::route('admin.scheduled_programs.index');
}
}