Thank you for this information.
Derick Rethans schrieb:
On Tue, 7 Apr 2009, Christoph Friedrich wrote:
as I could see in the example tutorial of the MvcTools Documentation
there is currently only URI Based routing.
Is the a way to implement Hostname Based routing?
For example: http://foo.bar.ez.no should call action "display" on
controller "main" with parameters "what" set to "foo.bar"
So that someone could implement an admin interface onto a subdomain.
It's quite trivial to do this, but you need to inherit the
ezcMvcRailsRoute class and overload match(). Something like the code
below. Notice that there is only one line changed with the standard
ezcMvcRailsRoute class' match() function. I think we should refactor
this so that it's easier to just override that specific bit. I'll try to
do that in an upcoming commit:
class myMvcRoute extends ezcMvcRailsRoute
{
/**
* This method performs the actual pattern match against the $request's
* URI.
*
* @param ezcMvcRequest $request
* @param array(string) $matches
* @return bool
*/
protected function match( $request, &$matches )
{
$matches = array();
// first we split the pattern and request ID per /
$patternParts = explode( '/', $this->pattern );
$requestParts = explode( '/', $request->requestId ); /* changed from
$request->uri */
// if the number of / is not the same, it can not match
if ( count( $patternParts ) != count( $requestParts ) )
{
return false;
}
// now loop over all parts of the pattern, and see if it matches with
// the request URI
foreach ( $patternParts as $id => $patternPart )
{
if ( $patternPart == '' || $patternPart[0] != ':' )
{
if ( $patternPart !== $requestParts[$id] )
{
return false;
}
}
else
{
if ( $requestParts[$id] == '' )
{
return false;
}
$matches[substr( $patternPart, 1 )] = $requestParts[$id];
}
}
return true;
}
}
regards,
--
Components mailing list
Components@lists.ez.no
http://lists.ez.no/mailman/listinfo/components