PHP Classes

I had looked through the example file to this package and I t...

Recommend this page to a friend!

      icRouter  >  All threads  >  I had looked through the example...  >  (Un) Subscribe thread alerts  
Subject:I had looked through the example...
Summary:Package rating comment
Messages:6
Author:sergey
Date:2011-05-03 07:58:20
Update:2011-05-04 09:45:14
 

sergey rated this package as follows:

Utility: Insufficient
Consistency: Not sure
Unit tests: Not sure

  1. I had looked through the example...   Reply   Report abuse  
Picture of sergey sergey - 2011-05-03 07:58:20
I had looked through the example file to this package and I though It's so hard to understand the routing intuitively. I'm working on my framework on PHP and I just declare two functions to generate route tips. It looks like something this:
map.connect('/',array('controller' => 'index', 'action' => 'view', 'method' => 'GET'));
map.rule('/blog/{controller}/{action}',array('method' => 'GET'));
Nothing more - it's usefull and simply to understand I think.

  2. Re: I had looked through the example...   Reply   Report abuse  
Picture of Igor Crevar Igor Crevar - 2011-05-03 09:01:29 - In reply to message 1 from sergey
Yes, i know and realize that it could be simple but i wanted to achieve some powerful(in my opinion) things with this routing.
For example when you create two router parameters:
$pRPSlug = new icRouteParameter(icRouteParameter::REG_REPLACE, 'A-Za-z\-_0-9' );
$oRPInt = new icRouteParameter(icRouteParameter::INT);

and add simple route(well its always complicated they yours :) )

$oRouter->addRoute( new icRoute( 'photo_show', '/photo/:id-:name', NULL, array('id' => $oRPInt, 'name' => $oRPSlug));

when you call for example generating url:
$oRouter->generate('photo', 'id=33e&name= This is real name');

it will convert name to This-is-real-name and id to 33.

Also this url will be not matched
/photo/one-two
,but this will
/photo/10-name-of-the-photo

This is why all parameters must be specialized in array. 3rd parameter(NULL) is to signalize icRoute to generate REGEX pattern for matching. This is not fast operation so I live option to myself(or any other programmer) to send this parameter directly.



  3. Re: I had looked through the example...   Reply   Report abuse  
Picture of sergey sergey - 2011-05-03 09:17:23 - In reply to message 2 from Igor Crevar
It's can be done much much easier to foreign programmers to define the route just to specify a simple interfaces and include some logic. And if the programmer will need to call only one class methods (IMHO). I do no want to offend you but If it's a part of framework it's must be easy to understand how to use it, and I don't want to remember all methods and objects names. IMHO framework must simplify the developing.

  4. Re: I had looked through the example...   Reply   Report abuse  
Picture of Igor Crevar Igor Crevar - 2011-05-03 10:13:57 - In reply to message 3 from sergey
You got a point.
I will add possibility to specify route with simple

$oRouter->addRoute( new icRoute( 'routename', '/:module/:action') );

This means i will just internally generate default parameters if they are not specified explicitly. Its easy because default parameters for route
/:module/:action will internally generated as array('module' => NULL, 'action' => NULL);

But i will also allow developer to specify parameters on his own.

Thanks for remarks and suggestions.

  5. Re: I had looked through the example...   Reply   Report abuse  
Picture of Igor Crevar Igor Crevar - 2011-05-03 10:16:10 - In reply to message 4 from Igor Crevar
Offcourse default values for those parameters(module and action in prev example) will(and can) be specify in another array...

  6. Re: I had looked through the example...   Reply   Report abuse  
Picture of Igor Crevar Igor Crevar - 2011-05-04 09:45:15 - In reply to message 5 from Igor Crevar
Hi,
I made changes you suggested, so now routes can be built with something like:

$oRouter->addRoute( new icRoute( 'photo', '/photo/:view' ) );

$oRouter->generate('photo', 'view=list');
will generate url /photo/list

or specify some default matchings

$oRouter->addRoute( new icRoute( 'video', '/video/:view/:id', array('id' => 0 ) ) );

$oRouter->generate('video', 'view=list');
will generate /video/list (note that id is not in the url because its default!!)

$oRouter->generate('video', array('view' => 'show', 'id' => 100) );
will generate /video/show/100



Type of parameters, reg ex expression can be also specified in route constructor(faster, save processing by php) but this is for advanced usage.

Of course this routing system is complex, so its not champion in speed or performances.

Can you try again and tell me what you think?