-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
URL Routing #2920
Comments
yeah, i think it would be useful, but can you describe in particular what you want to bring here ? would be great if you will provide list with examples . |
The url routing in laravel is very interesting. It uses a separate file for handling routing. We can group urls and add filters for the urls. Below is the url routes that I used in one of my projects. If we can have this kind of url handling in Yii, it would certainly make Yii even better framework. Route::group(array('prefix' => 'admin', 'before' => 'auth.admin'), function()
{
Route::get('notallowed', array('as'=>'admin.notallowed', 'uses'=>'App\Controllers\Admin\AdminController@notAllowed'));
Route::get('dashboard', array('as'=>'admin.dashboard', 'uses'=>'App\Controllers\Admin\AdminController@showDashboard'));
/**
* routes for logged in user
*/
Route::get('changepassword', array('as'=>'admin.changepassword', 'uses'=>'App\Controllers\Admin\UserController@changePassword'));
Route::post('changepassword', array('as'=>'admin.postchangepassword', 'uses'=>'App\Controllers\Admin\UserController@postChangePassword'));
Route::group(array('before'=>'sentry'), function()
{
/**
* routes for units
*/
Route::get('units', array('as'=>'admin.units', 'uses'=>'App\Controllers\Admin\UnitController@showIndex'));
Route::get('units/create', array('as'=>'admin.units.create', 'uses'=>'App\Controllers\Admin\UnitController@getCreate'));
Route::post('units/create', array('as'=>'admin.units.postCreate', 'uses'=>'App\Controllers\Admin\UnitController@postCreate'));
Route::get('units/update/{id}', array('as'=>'admin.units.update', 'uses'=>'App\Controllers\Admin\UnitController@get_update'));
Route::post('units/update/{id}', array('as'=>'admin.units.postUpdate', 'uses'=>'App\Controllers\Admin\UnitController@postupdate'));
Route::post('units/delete/{id}', array('as'=>'admin.units.delete', 'uses'=>'App\Controllers\Admin\UnitController@postDelete'));
Route::post('units/deleteAll/{id}', array('as'=>'admin.units.deleteAll', 'uses'=>'App\Controllers\Admin\UnitController@deleteAll'));
Route::get('units/listunits', array('as'=>'admin.units.listunits', 'uses'=>'App\Controllers\Admin\UnitController@listunits'));
}
} This way, we can have same url performing different action based upon the request method. And also, have a certain code run before or after the action is performed. I had difficulty in managing/handling urls in Yii 1.13 in one of the projects I did. Another interesting feature can be different configuration files based upon the setup environment. Developers tend to have their own configuration. When collaborating in a project, the configuration file often tends to be overwritten. So, if there was system specific configuration file, then it would make life easier for the developers. Installation via composer is definitely a good news. |
Easily done with Yii via simple
Is it assigning internal ID for a route? I'd not implement it since it's hard to manage these associations. In Yii it is assigned automatically to
That seems to be mapping route to controller action. Again, in Yii there's convention for it i.e.
Looks handy. Currently can be achieved with beforeAction but it can be wise to move it to rules. Not sure about it yet.
What is it for?
Yii supports it as well. The form is different though: ['pattern' => 'changepassword', 'route' => 'user/changePassword', 'verb' => 'GET'],
['pattern' => 'changepassword', 'route' => 'user/postChangePassword', 'verb' => 'POST'],
Already implemented in advanced app template. |
Thanks. Your email gave me new ideas. array('prefix' => 'admin', This groups the urls so that we don't have to make same kind of rules. Route::get('admin/units', array('as'=>'admin.units',
'uses'=>'App\Controllers\Admin\UnitController@showIndex'));
Route::get('admin/units/create', array('as'=>'admin.units.create',
'uses'=>'App\Controllers\Admin\UnitController@getCreate'));
Route::post('admin/units/create',
array('as'=>'admin.units.postCreate',
'uses'=>'App\Controllers\Admin\UnitController@postCreate')); We can write like: Route::group(array('prefix' => 'admin', 'before' => 'auth.admin'),
function()
{
Route::get('units', array('as'=>'admin.units',
'uses'=>'App\Controllers\Admin\UnitController@showIndex'));
Route::get('units/create', array('as'=>'admin.units.create',
'uses'=>'App\Controllers\Admin\UnitController@getCreate'));
Route::post('admin/units/create',
array('as'=>'admin.units.postCreate',
'uses'=>'App\Controllers\Admin\UnitController@postCreate'));
}); I also like the automatic mapping of actions into url, but I think how |
@samdark example with controller is about how explicitly match route to the given controller. In Yii2 currently this is not possible, only with |
Is this available in Yii 1.13? ['pattern' => 'changepassword', 'route' => 'user/changePassword', 'verb' => 'GET'], |
@bSushil yes. |
yes, Yii2 always follows convention and I think that's cleaner, leaves less space for errors and easier to work with project.
The question was about different route config files depending on environments. Implementation is here: https://github.com/yiisoft/yii2/blob/master/apps/advanced/init |
@samdark not sure about first one, it can be useful for already existing solutions or modules that have controllers, and user will not be needed to change things in 2 places: |
Related with #1763 i think ) |
Closed as we do not have plan to change our existing URL routing. The design described here has its own pros and cons. |
I think url routing in Yii 1.* is not that good. After working in Laravel, I really liked how it handles url routing. I wish if something like that is implemented in Yii 2.
The text was updated successfully, but these errors were encountered: