Pattern matching method and parameters in url

74 views
Skip to first unread message

Kendall Arneaud

unread,
Jul 31, 2013, 12:03:33 PM7/31/13
to glu...@googlegroups.com
I'm trying to create a pattern matching scenario where you match  a url such as

'/events/display/9382817/featured/' => 'events'

to the event method and parameter match

Array (
['method'] => 'display',
['parameter'] => Array([0] => 9382817, [1]=> 'featured');

I have this partial expression 

^/(?P<method>.*?)/(?P<parameter>.*?)
 But it doesn't quite work. I am not good at regex

I believe with this pattern we can then alter line

if (class_exists($class)) {
                        $obj = new $class;
                        if (method_exists($obj, $method)) {
                            $obj->$method($matches);
                        } else {

to something like

if (class_exists($class)) {
                        $obj = new $class;
                            $method = $matches['method'] || $method;
                            $params = $matches['parameter'] || null
                        if (method_exists($obj, $method)) {
                            $obj->$method($params);
                        } else {
 

We can probably link url to class method logic

Please help/ advise 

Joe Topjian

unread,
Jul 31, 2013, 5:18:43 PM7/31/13
to glu...@googlegroups.com
Hi Kendall,

It's possible your .*'s in your regex are being too greedy. How about replacing them with \w (for a single word) and \d (for a digit)?

Joe


--
You received this message because you are subscribed to the Google Groups "GluePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gluephp+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Kendall Arneaud

unread,
Jul 31, 2013, 6:21:32 PM7/31/13
to glu...@googlegroups.com
/events/(?P<method>.*?)/(?P<parameter>.*)

I tried but I am using the above as the solution then explode() <parameter> 

was worth a shot
Reply all
Reply to author
Forward
0 new messages