sirin_ibin
(Sirinibin2006)
June 19, 2014, 1:49am
21
samdark:
Why GET format should be different from PATH? Do you think we need to keep GET format in Yii2 (is it actually used)?
I don’t like hardcoding any part of URLs.
Generally I think module should be able to provide URL rules and application should be able to override these rules. This way one will be able to use full-blown module while customizing its URLs.
Currently this behavior can be achieved with something like:
'onBeginRequest'=>function($event){
$route=Yii::app()->getRequest()->getPathInfo();
$module=substr($route,0,strpos($route,'/'));
if(Yii::app()->hasModule($module))
{
$module=Yii::app()->getModule($module);
if(isset($module->urlRules))
{
$urlManager=Yii::app()->getUrlManager();
$urlManager->addRules($module->urlRules);
}
}
return true;
},
Thansk alot for this code… Worked well for me…
i was trying to apply few Rules specifically for a my api module…
konapaz
(Konapaz)
October 8, 2014, 9:15am
22
Look this rule
‘<module:\w+>/<controller:\w+>/<action>/<id:\d+>’=>’<module>/<controller>/<action>’,
Works for me in all modules, controllers and actions with modules
qiang:
Module can be considered as a self-contained application within another application. As a result,. it also participates in URL parsing and creation.
In 1.x, all URL parsing and creation are done at the application level. Module has little control about that.
In 2.0, I’m thinking to let module control its own URL parsing and creation. In particular:
If application url manager is set as GET format, then module url manager is ignored
If application url manager is set as PATH format, then[list]
URL creation within the module will be handled by the module URL manager unless it is using GET format.
When parsing a URL, if the first segment in the path info is a module ID, then[list]
If the module URL manager is in PATH format, the corresponding module will handle the rest part of the URL parsing. For example, path info ‘comment/x/yz’ will be handled by ‘comment’ module’s url manager which sees ‘x/y/z’ as the path info.
Otherwise, the application URL manager will continue parsing the URL.
[/list][/list]
What do you think about this proposal?
This has the benefit of making URL rule management less centric and giving modules more freedom in determining what URL formats to use.
The main drawback is that the module ID is now hardcoded in the URLs. Do you think this is acceptable?
Thats the zend2 approach, like it.
Would that also mean that one is ultimately putting less rules in the main config therefore speeding up load time?
samdark
(Alexander Makarov)
October 22, 2014, 3:14pm
25
Putting less rules — yes. Speeding up — no since you have to check rules regardless of their source.
nisteve
(Steve)
May 7, 2015, 8:26am
26
Qiang this would be an excellent feature!
We have built many apps using Yii from small to very large complex apps modules are essential and this is precisely how we currently use Yii 1. Each module has a startup and we override the rules there… But it would be excellent to have this lower in the framework.
Is this currently in Yii 2.0 now? Did it get implemented?
rssreader
(rssreader)
November 27, 2019, 3:01pm
27
I have set
defaultRoute = “mainnewmodule”;
URL https://www.example.com/default/index => mainnewmodule/controllers/DefaultController::actionIndex
Works OK.
But:
URL https://www.example.com/mainnewmodule/default/index
returns the same content. How to disable this duplication? I don’t want to use a URL “https://www.example.com/mainnewmodule ”. What is the easiest solution?
Thanks for help.