|
|
| |
1. Rule Matching Problem |
|
Reply |
|
|
 Prasun Paul | 2007-08-07 07:37:49 |
Hello!
I'm Gregory and I now played with your class for 2 days.
Now I tried sth like that:
<code>
$pattern = "hotel/:province/:city/:hotel/:action";
$rules = array(
"action"=>'(([a-zA-Z]){4,}\.html)$');
$defaults = array(
'module'=>'location',
"location_type"=>'hotel',
'province'=>'null',
'city'=>'null',
'hotel'=>'null',
'action'=>'index');
$upm->addPattern('test', $pattern, $rules, $defaults);
$upm->setSubjectUrl('hotel/kujawsko-pomorskie/warszawa/hotel/komentuj.html');
echo "Attributes of
<b>hotel/kujawsko-pomorskie/warszawa/hotel/komentuj.html</b>"."<br>";
print_r($upm->getAttributes());
$upm->setSubjectUrl('hotel/kujawsko-pomorskie/warszawa/hotel');
echo "Attributes of
<b>hotel/kujawsko-pomorskie/warszawa/hotel</b>"."<br>";
print_r($upm->getAttributes());
$upm->setSubjectUrl('hotel/kujawsko-pomorskie/warszawa');
echo "Attributes of <b>hotel/kujawsko-pomorskie/warszawa</b>"."<br>";
print_r($upm->getAttributes());
$upm->setSubjectUrl('hotel/kujawsko-pomorskie/list.html');
echo "Attributes of <b>hotel/kujawsko-pomorskie/list.html</b>"."<br>";
print_r($upm->getAttributes());
$upm->setSubjectUrl('hotel/kujawsko-pomorskie/');
echo "Attributes of <b>hotel/kujawsko-pomorskie/</b>"."<br>";
print_r($upm->getAttributes());
$upm->setSubjectUrl('hotel/list.html');
echo "Attributes of <b>hotel/list.html</b>"."<br>";
print_r($upm->getAttributes());
$upm->setSubjectUrl('hotel');
echo "Attributes of <b>hotel</b>"."<br>";
print_r($upm->getAttributes());
</code>
My problem is that city and hotel have the same pattern, and province
have 66% match for city and hotel. And how you can see on your computer
the param action is not well cached.
My vision pattern:
/:province can be:
1) from 8 to 18 letter
OR
2) from 8 to 9 letter then "-" then 8 letter
OR
3) empty
/:city and /:hotel
1) minimum 3 letter
OR
2) minimum 3 letter then "-" minimum 3 letter
OR
3) minimum 3 letter then "-" minimum 3 letter then "-" then minmum 3
letter
OR
4) empty
/:action
1) have ".html" in name
OR
2) empty
I'll tried to make more pattern rules like:
hotel/:action
hotel/:province/:action
hotel/:province/:city
hotel/:province/:city/:action
hotel/:province/:city/:hotel
hotel/:province/:city/:hotel/:action
but the last pattern catched all links which started with "hotel/"
For help with solution with my problem thank you in advance
p.s. excuse me for my ugly english ;-)
gregory from Poland
|
| |
2. Re: Rule Matching Problem |
|
Reply |
|
|
 Prasun Paul | 2007-08-07 07:39:26 - In reply to message 1 from Prasun Paul |
/**************Solution1****************/
$upm = new UrlPatternManager();
$pattern = "hotel/:province/:city/:hotel/:action";
$rules = array("action"=>'(([a-zA-Z]{4,})\.html)');
/**
* be careful to define defaults. if it contains any friendly URL attribute name
* then the class will generate an optional subpattern
*/
$defaults = array(
'module'=>'location',
"location_type"=>'hotel'
);
$upm->addPattern('test1', $pattern, $rules, $defaults);
$pattern = "hotel/:province/:city/:hotel";
$rules = array();
/**
* be careful to define defaults. if it contains any friendly URL attribute name
* then the class will generate an optional subpattern
*/
$defaults = array(
'module'=>'location',
"location_type"=>'hotel');
$upm->addPattern('test2', $pattern, $rules, $defaults);
$upm->setSubjectUrl('hotel/kujawskopomorskie/warszawa/hotel/komentuj.html');
echo "Attributes of
<b>hotel/kujawskopomorskie/warszawa/hotel/komentuj.html</b>"."<br>";
print_r($upm->getAttributes());
$upm->setSubjectUrl('hotel/kujawsko-pomorskie/warszawa/hotel');
echo "Attributes of
<b>hotel/kujawsko-pomorskie/warszawa/hotel</b>"."<br>";
print_r($upm->getAttributes());
/**************Solution2****************/
$upm = new UrlPatternManager();
$pattern = "hotel/prov/:province/cty/:city/htl/:hotel/:action";
$rules = array("action"=>'(([a-zA-Z]{4,})\.html)');
$defaults = array(
'module'=>'location',
"location_type"=>'hotel',
'province'=>null,
'city'=>null,
'hotel'=>null,
'action'=>'index');
$upm->addPattern('test1', $pattern, $rules, $defaults);
$pattern = "hotel/prov/:province/cty/:city/htl/:hotel";
$rules = array();
$defaults = array(
'module'=>'location',
"location_type"=>'hotel',
'province'=>null,
'city'=>null,
'hotel'=>null,
'action'=>'index');
$upm->addPattern('test2', $pattern, $rules, $defaults);
$upm->setSubjectUrl('hotel/prov/kujawskopomorskie/cty/warszawa/htl/hotel/komentuj.html');
echo "Attributes of <b>hotel/prov/kujawskopomorskie/cty/warszawa/htl/hotel/komentuj.html</b>"."<br>";
print_r($upm->getAttributes());
$upm->setSubjectUrl('hotel/prov/kujawsko-pomorskie/cty/warszawa/htl/hotel');
echo "Attributes of <b>hotel/prov/kujawsko-pomorskie/cty/warszawa/htl/hotel</b>"."<br>";
print_r($upm->getAttributes()); |
| |
3. Re: Rule Matching Problem |
|
Reply |
|
|
 Grzegorz Rygielski | 2007-08-10 14:21:10 - In reply to message 2 from Prasun Paul |
Thank you, now it works almostly fine!
Almostly because when in /:action i use "-" the pattern fail.
For example test-1.0-10.html, I've tried:
$rules =("action"=>'[\d\-]{4,}(\.html)$');
but it fails.
when I use preg_match('/[\d\-]{4,}(\.html)$/','test-10-10.htm') it return true. |
| |
4. Re: Rule Matching Problem |
|
Reply |
|
|
 Prasun Paul | 2007-08-10 17:31:04 - In reply to message 3 from Grzegorz Rygielski |
>>when I use preg_match('/[\d\-]{4,}(\.html)$/','test-10-10.htm') it return true
Actually the reg exp: '/[\d\-]{4,}(\.html)$/' mathches with '10-10.htm' and thts y "preg_match" returns true. But the reg exp does not match with the whole subject 'test-10-10.htm'. You can try with '/[\s\d\-]{4,}(\.html)$/'.
|
| |
5. Re: Rule Matching Problem |
|
Reply |
|
|
 Prasun Paul | 2007-08-10 17:37:49 - In reply to message 4 from Prasun Paul |
| Sorry, I have forgotten one thing to inform. Any rule should never include '$' for eample '/[\s\d\-]{4,}(\.html)$/' is not valid but '/[\s\d\-]{4,}(\.html)/'. is a valid rule. The class will automatically append '$' when necessary. |
|