Hi, I was wondering if anyone could help me with a small problem I am having with URLs
I have several modules which are used largely as stand alone applications (admin is on a different domain for security, multiple websites etc). What I want to do that I can’t seem to figure out is map a module to a URL.
I got most of the way with URL rules but ran into some problems:
I use multiple different action parameters and sometimes more than one so my rules have to include every variation which is not useful - I would like Yii’s default handling just to work and assume /admin. I have specific error handlers for each module and this means if an erroneous path does not conform to one of Yii’s rules for the module then the default error handler is called.
I have tried mapping all requests to admindomain.com to /admin with a rule like:
But it did not work. Can anyone tell me is there a way to make yii work as normal but just assume a module path when on this domain - if I could get that it would solve a lot of problems.
Thanks Ankit for the reply but I think you may have missed my goal here.
I have a working solution now that I just need to test and improve. For anyone else stuck with this or anyone who can improve this here is what I have done:
class AdminUrlRule extends CBaseUrlRule
{
public function createUrl($manager, $route, $params, $ampersand)
{
return false;
// Haven't tackled this yet
}
public function parseUrl($manager, $request, $pathInfo, $rawPathInfo)
{
// Get the requested domain
$domain = strtolower($request->getHostInfo());
if(strpos($domain, 'admindomain.com')) {
// Return the path with "/admin" prepended to it
return '/admin' . rtrim('/' . $pathInfo, '/') . '/';
} else {
// Admin domain not requested so don't use this rule
return false;
}
}
}
This means that the request comes out of the class with the path adjusted for the module and then Yii continues as normal. What I need to do here is refactor this to allow different modules and figure out the createUrl method. Any opinions are welcome.