Page 1 of 1
register route not working
Posted: Fri May 15, 2009 8:06 am
by piotrekkr
Why this routes:
Code: Select all
$this->RegisterRoute('/galeria-zwyciezcow(\/(?P<page>[0-9]+))?$/', array('returnid' => 28, 'action' => 'winner_gallery', 'inline' => 1));
or
Code: Select all
$this->RegisterRoute('/galeria-zwyciezcow\/(?P<page>[0-9]+)?$/', array('returnid' => 28, 'action' => 'winner_gallery', 'inline' => 1));
aren't working for links like:
Code: Select all
http://domain.com/galeria-zwyciezcow
http://domain.com/galeria-zwyciezcow/
but works for link:
Code: Select all
http://domain.com/galeria-zwyciezcow/1
Any ideas? Thanks for help

Re: register route not working
Posted: Tue May 19, 2009 8:14 am
by plger
(Off the top of my head) Have you tried
Code: Select all
'/galeria-zwyciezcow\/(?P<page>[0-9]+?)$/'
?
Re: register route not working
Posted: Fri May 22, 2009 6:08 am
by piotrekkr
adding "?" after "+" only makes "+" ungreedy so it doesn't solve problem

Re: register route not working
Posted: Tue Jun 02, 2009 6:47 am
by piotrekkr
Ok I found problem... Problem is in index.php in line like this:
Code: Select all
//See if our page matches any predefined routes
$page = rtrim($page, '/');
//See if our page matches any predefined routes
$page = rtrim($page, '/');
if (strpos($page, '/') !== FALSE)
{
$routes =& $gCms->variables['routes'];
$matched = false;
foreach ($routes as $route)
{
$matches = array();
if (preg_match($route->regex, $page, $matches))
{
//Now setup some assumptions
if (!isset($matches['id']))
$matches['id'] = 'cntnt01';
if (!isset($matches['action']))
$matches['action'] = 'defaulturl';
if (!isset($matches['inline']))
$matches['inline'] = 0;
if (!isset($matches['returnid']))
$matches['returnid'] = ''; #Look for default page
if (!isset($matches['module']))
$matches['module'] = $route->module;
//Get rid of numeric matches
foreach ($matches as $key=>$val)
{
if (is_int($key))
{
unset($matches[$key]);
}
else
{
if ($key != 'id')
$_REQUEST[$matches['id'] . $key] = $val;
}
}
//Now set any defaults that might not have been in the url
if (isset($route->defaults) && count($route->defaults) > 0)
{
foreach ($route->defaults as $key=>$val)
{
$_REQUEST[$matches['id'] . $key] = $val;
if (array_key_exists($key, $matches))
{
$matches[$key] = $val;
}
}
}
//Get a decent returnid
if ($matches['returnid'] == '') {
global $gCms;
$contentops =& $gCms->GetContentOperations();
$matches['returnid'] = $contentops->GetDefaultPageID();
}
$_REQUEST['mact'] = $matches['module'] . ',' . $matches['id'] . ',' . $matches['action'] . ',' . $matches['inline'];
$page = $matches['returnid'];
$smarty->id = $matches['id'];
$matched = true;
}
}
if (!$matched)
{
$page = substr($page, strrpos($page, '/') + 1);
}
}
When I add route like:
Code: Select all
'/galeria-zwyciezcow\/(?P<page>[0-9]+)?$/'
or
'/gallery\/?'
or anything that do not need '/' between start and end of route
and request '
http://host.com/gallery/' or '
http://host.com/gallery' it won't work.
IMHO it's bug.
.htaccess rewrite this to
http://host.com?page=gallery/
next in index.php it is right trimmed so
next
is always false so routes are ommited...
I think routes should be checked always first (regardless if there is '/' or not) before checking a page alias etc.
Re: register route not working
Posted: Thu Jun 04, 2009 3:33 pm
by duclet
The problem that it is not working is because of the + which means it requires 1 or more. If you don't need it, it should be *. Though last I checked, it might need to be *+.
Re: register route not working
Posted: Thu Jun 04, 2009 4:46 pm
by piotrekkr
No i tried '*' etc. Problem isn't there. Try make route that not need to have '/' within. For example:
Code: Select all
$this->RegisterRoute('/archive\/?$/', array('returnid' => 28, 'action' => 'archive', 'inline' => 1));
or
$this->RegisterRoute('/profile$/', array('returnid' => 28, 'action' => 'archive', 'inline' => 1));
or any route that not need '/' between start and end.
won't work but this will:
Code: Select all
$this->RegisterRoute('/profile\/1$/', array('returnid' => 28, 'action' => 'archive', 'inline' => 1))
or
$this->RegisterRoute('/profile\/something-after-slash$/', array('returnid' => 28, 'action' => 'archive', 'inline' => 1))