Search the web
Sign In
New User? Sign Up
phpexperts
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
How you manage your url in php application ? (for CodeIgnitor guys)   Topic List   < Prev Topic  |  Next Topic >
Summarize Messages Sort by Date  
#12057 From: "hasan83bd" <hasan83bd@...>
Date: Mon May 18, 2009 7:09 pm
Subject: How you manage your url in php application ? (for CodeIgnitor guys)
hasan83bd
Offline Offline
Send Email Send Email
 
Hi,
It has been long while since i last post here in phpexperts group, well i was
away from php for pretty long, being more java and ruby on rails guy when i got
chance to help few php projects, i borrowed few more neat and nifty design
concept from rails to php.

well let me tell you about the story of stories, i ain't treat myself as php
expert anymore since being detached or keeping my ass out of it. i'd prefer to
call myself as the expert of "work for fun".

before digging into the details let me explain what was wrong and what could be
wrong with your current way of using URL through out the php application (web
site)

-> Karim, he is given a task to develop a beautiful WOW WOW application in php,

-> He is very WOW WOW developer, develops everything on the fly, produces
(TR/Z/B)*illion of bugs on the fly as well.

-> Very promonient developer, he knows how to write php along html, after
hearing several good advices he started giving CodeIgnitor a shot.

-> So he used to write the following kinda code in everywhere -

<a href="<?= site_url("user/profile/10") ?>">My profile</a>

Now if you get a chance to look into his view or controller codes, you might see
in everywhere he hard coded the url pattern.

what the hell is the URL Pattern?

well, you see "site_url("user/profile/10")" this code is expanded to
"http://abc.com/user/profile/10" while you execute your code in php. this
"user/profile/:number" is called url pattern.

everywhere in his code base he kept such hard coded url pattern.
let's imagine his client or boss or team lead ask him to change the url pattern
"user/profile/:number" to something similar "profile/:number/".

now tell me what would YOU DO? if you were placed in such situation?

well you know if that guy was me, i'd run a string replace command through out
the whole project. so wherever i wrote "user/profile/:number" url pattern that
would be converted to "profile/:number"

something like this - /site_url\("user\/profile\/(\d+)"\)/ replace to
site_url("profile/$1")


well i guess many of you already have such problem with similar solution ;)
frankly speaking we had similar problem thus we came up with some solution where
we can change URL pattern without modifying existing view or controller code.

here is the evidence -
<a href="<?= $this->url->profile(array("username" => $user_profile->username))
?>">
<img src="<?= $this->url->avatar(array("username" => $user_profile->username))
?>" />
</a>

you see, we ain't hard coding any url anymore, rather we are calling a function
which are automatically generating from the following kinda configuration -
$urls["profile"] = "http://:username.:host/community";
$urls["avatar"] = "http://avatar.somewherein.net/avatar/:username/for/aawaj";
$urls["logout"] = "logout";

i am pretty sure you guys are smart enough to figure out how we did that, let me
know if you need any help about how we did that.

well first you try yourself and tell me how we did :)

best wishes,
nhm tanveer hossain khan (hasan)
http://hasan.we4tech.com
twit @we4tech
work for fun!




#12058 From: Tareq Hasan <tareq1988@...>
Date: Mon May 18, 2009 7:25 pm
Subject: Re: [phpXperts] How you manage your url in php application ? (for CodeIgnitor guys)
tareq.hasan
Offline Offline
Send Email Send Email
 
Great post hasan vai. It might be your blog post also :P
--------------------------------------------
Best regard
Tareq Hasan
My Blog (http://tareq.weDevs.com)
Developers forum: (http://forum.weDevs.com)
Follow me: (http://twitter.com/tareq_cse)


On Tue, May 19, 2009 at 1:09 AM, hasan83bd <hasan83bd@...> wrote:


Hi,
It has been long while since i last post here in phpexperts group, well i was away from php for pretty long, being more java and ruby on rails guy when i got chance to help few php projects, i borrowed few more neat and nifty design concept from rails to php.

well let me tell you about the story of stories, i ain't treat myself as php expert anymore since being detached or keeping my ass out of it. i'd prefer to call myself as the expert of "work for fun".

before digging into the details let me explain what was wrong and what could be wrong with your current way of using URL through out the php application (web site)

-> Karim, he is given a task to develop a beautiful WOW WOW application in php,

-> He is very WOW WOW developer, develops everything on the fly, produces (TR/Z/B)*illion of bugs on the fly as well.

-> Very promonient developer, he knows how to write php along html, after hearing several good advices he started giving CodeIgnitor a shot.

-> So he used to write the following kinda code in everywhere -

<a href="<?= site_url("user/profile/10") ?>">My profile</a>

Now if you get a chance to look into his view or controller codes, you might see in everywhere he hard coded the url pattern.

what the hell is the URL Pattern?

well, you see "site_url("user/profile/10")" this code is expanded to "http://abc.com/user/profile/10" while you execute your code in php. this "user/profile/:number" is called url pattern.

everywhere in his code base he kept such hard coded url pattern.
let's imagine his client or boss or team lead ask him to change the url pattern "user/profile/:number" to something similar "profile/:number/".

now tell me what would YOU DO? if you were placed in such situation?

well you know if that guy was me, i'd run a string replace command through out the whole project. so wherever i wrote "user/profile/:number" url pattern that would be converted to "profile/:number"

something like this - /site_url\("user\/profile\/(\d+)"\)/ replace to site_url("profile/$1")

well i guess many of you already have such problem with similar solution ;) frankly speaking we had similar problem thus we came up with some solution where we can change URL pattern without modifying existing view or controller code.

here is the evidence -
<a href="<?= $this->url->profile(array("username" => $user_profile->username)) ?>">
<img src="<?= $this->url->avatar(array("username" => $user_profile->username)) ?>" />
</a>

you see, we ain't hard coding any url anymore, rather we are calling a function which are automatically generating from the following kinda configuration -
$urls["profile"] = "http://:username.:host/community";
$urls["avatar"] = "http://avatar.somewherein.net/avatar/:username/for/aawaj";
$urls["logout"] = "logout";

i am pretty sure you guys are smart enough to figure out how we did that, let me know if you need any help about how we did that.

well first you try yourself and tell me how we did :)

best wishes,
nhm tanveer hossain khan (hasan)
http://hasan.we4tech.com
twit @we4tech
work for fun!



#12061 From: Himel Nag Rana <h_n_rana@...>
Date: Tue May 19, 2009 4:07 am
Subject: Re: [phpXperts] How you manage your url in php application ? (for CodeIgnitor guys)
h_n_rana
Online Now Online Now
Send Email Send Email
 
Dear Hasan Vai,
                          I have a question for you regarding the url issue for codeigniter. 
I got your point of ease of managing urls. The question is regarding performance.
Whenever any url is clicked or hit, the url->profile() function is being called. so for a large site we have to store a large number of url pattern. Is there a chance of performance hampering? Is it possible to use some config constant and call the functions for assigning their values? So that the functions are called only once?

We use routes for url shortening or pattern matching. But haven't use your technique in project till now.

Waiting for you reply.
 
Thanks and Regards ----
Himel Nag Rana
Cell: 01711664049,



From: hasan83bd <hasan83bd@...>
To: phpexperts@yahoogroups.com
Sent: Tuesday, May 19, 2009 1:09:32 AM
Subject: [phpXperts] How you manage your url in php application ? (for CodeIgnitor guys)

Hi,
It has been long while since i last post here in phpexperts group, well i was away from php for pretty long, being more java and ruby on rails guy when i got chance to help few php projects, i borrowed few more neat and nifty design concept from rails to php.

well let me tell you about the story of stories, i ain't treat myself as php expert anymore since being detached or keeping my ass out of it. i'd prefer to call myself as the expert of "work for fun".

before digging into the details let me explain what was wrong and what could be wrong with your current way of using URL through out the php application (web site)

-> Karim, he is given a task to develop a beautiful WOW WOW application in php,

-> He is very WOW WOW developer, develops everything on the fly, produces (TR/Z/B)*illion of bugs on the fly as well.

-> Very promonient developer, he knows how to write php along html, after hearing several good advices he started giving CodeIgnitor a shot.

-> So he used to write the following kinda code in everywhere -

<a href="<?= site_url("user/ profile/10" ) ?>">My profile</a>

Now if you get a chance to look into his view or controller codes, you might see in everywhere he hard coded the url pattern.

what the hell is the URL Pattern?

well, you see "site_url("user/ profile/10" )" this code is expanded to "http://abc.com/user/profile/10" while you execute your code in php. this "user/profile/ :number" is called url pattern.

everywhere in his code base he kept such hard coded url pattern.
let's imagine his client or boss or team lead ask him to change the url pattern "user/profile/ :number" to something similar "profile/:number/ ".

now tell me what would YOU DO? if you were placed in such situation?

well you know if that guy was me, i'd run a string replace command through out the whole project. so wherever i wrote "user/profile/ :number" url pattern that would be converted to "profile/:number"

something like this - /site_url\(" user\/profile\ /(\d+)"\) / replace to site_url("profile/ $1")

well i guess many of you already have such problem with similar solution ;) frankly speaking we had similar problem thus we came up with some solution where we can change URL pattern without modifying existing view or controller code.

here is the evidence -
<a href="<?= $this->url-> profile(array( "username" => $user_profile- >username) ) ?>">
<img src="<?= $this->url-> avatar(array( "username" => $user_profile- >username) ) ?>" />
</a>

you see, we ain't hard coding any url anymore, rather we are calling a function which are automatically generating from the following kinda configuration -
$urls["profile" ] = "http://:username.:host/community";
$urls["avatar" ] = "http://avatar. somewherein. net/avatar/ :username/ for/aawaj";
$urls["logout" ] = "logout";

i am pretty sure you guys are smart enough to figure out how we did that, let me know if you need any help about how we did that.

well first you try yourself and tell me how we did :)

best wishes,
nhm tanveer hossain khan (hasan)
http://hasan. we4tech.com
twit @we4tech
work for fun!



#12064 From: Anupom <anupom.nsu@...>
Date: Tue May 19, 2009 6:48 am
Subject: Re: [phpXperts] How you manage your url in php application ? (for CodeIgnitor guys)
ae_sumerians98
Offline Offline
Send Email Send Email
 
hi hasan,

i don't know how you guys exactly did this. but i can see the basic idea. i would like to share my 2 cents about your implementation (without seeing it fully anyway),

#1 the profile example ($this->url->profile) should have a 'host' key in your example, it's missing ;) you did not share your implementation but i guess you are handling this issue properly there. if a developer misses a key, then the system should raise an exception immediately. othewise you may end up with a URL like this http://hasan.:host/community. :P

#2. you are using ":" (colon) to determine the word to replace. : is a valid url encoded character and using it this way may lead to some issues later on. like suppose my url pattern is this, $urls["profile"] = "http://:username.:host/community/sortby:username"; in this case the later :username will get replaced too. or you applied some rocket science to avooid this sort of issues?

#3. i hope you are using some sort of caching mechanism in your implementatin. if your page has like > 1000 urls, then these str_replace/preg_replace etc will cost a lot. himel nag rana mentioned this in his mail already. many people had this issue with Rails earlier.

#4. use extensions in url when you are serving static contents (well even if they are dynamically produced). in your case this url does not have any extension - http://avatar.somewherein.net/avatar/:username/for/aawaj. some people may disagree with this by saying 'urls are supposed to identify a resource and not a particular format'. but hey then why don't we get rid of .js and .css extensions? and most servers can automatically determine the MIME type to send in the Content-Type header using the extnsion in the url. also i think it's more semantically correct - a particular resource can have different presentations and they should be determined through the extension, like as in Rails you can serve .xml, .json or .rdf or whatever from a single resource and the format is determined through the extension. also i guess it makes it easy for crawlers to determine the content type of the response.

thanks,

On Tue, May 19, 2009 at 10:07 AM, Himel Nag Rana <h_n_rana@...> wrote:


Dear Hasan Vai,
                          I have a question for you regarding the url issue for codeigniter. 
I got your point of ease of managing urls. The question is regarding performance.
Whenever any url is clicked or hit, the url->profile() function is being called. so for a large site we have to store a large number of url pattern. Is there a chance of performance hampering? Is it possible to use some config constant and call the functions for assigning their values? So that the functions are called only once?

We use routes for url shortening or pattern matching. But haven't use your technique in project till now.

Waiting for you reply.
 
Thanks and Regards ----
Himel Nag Rana
Cell: 01711664049,



From: hasan83bd <hasan83bd@...>
To: phpexperts@yahoogroups.com
Sent: Tuesday, May 19, 2009 1:09:32 AM
Subject: [phpXperts] How you manage your url in php application ? (for CodeIgnitor guys)

Hi,
It has been long while since i last post here in phpexperts group, well i was away from php for pretty long, being more java and ruby on rails guy when i got chance to help few php projects, i borrowed few more neat and nifty design concept from rails to php.

well let me tell you about the story of stories, i ain't treat myself as php expert anymore since being detached or keeping my ass out of it. i'd prefer to call myself as the expert of "work for fun".

before digging into the details let me explain what was wrong and what could be wrong with your current way of using URL through out the php application (web site)

-> Karim, he is given a task to develop a beautiful WOW WOW application in php,

-> He is very WOW WOW developer, develops everything on the fly, produces (TR/Z/B)*illion of bugs on the fly as well.

-> Very promonient developer, he knows how to write php along html, after hearing several good advices he started giving CodeIgnitor a shot.

-> So he used to write the following kinda code in everywhere -

<a href="<?= site_url("user/ profile/10" ) ?>">My profile</a>

Now if you get a chance to look into his view or controller codes, you might see in everywhere he hard coded the url pattern.

what the hell is the URL Pattern?

well, you see "site_url("user/ profile/10" )" this code is expanded to "http://abc.com/user/profile/10" while you execute your code in php. this "user/profile/ :number" is called url pattern.

everywhere in his code base he kept such hard coded url pattern.
let's imagine his client or boss or team lead ask him to change the url pattern "user/profile/ :number" to something similar "profile/:number/ ".

now tell me what would YOU DO? if you were placed in such situation?

well you know if that guy was me, i'd run a string replace command through out the whole project. so wherever i wrote "user/profile/ :number" url pattern that would be converted to "profile/:number"

something like this - /site_url\(" user\/profile\ /(\d+)"\) / replace to site_url("profile/ $1")

well i guess many of you already have such problem with similar solution ;) frankly speaking we had similar problem thus we came up with some solution where we can change URL pattern without modifying existing view or controller code.

here is the evidence -
<a href="<?= $this->url-> profile(array( "username" => $user_profile- >username) ) ?>">
<img src="<?= $this->url-> avatar(array( "username" => $user_profile- >username) ) ?>" />
</a>

you see, we ain't hard coding any url anymore, rather we are calling a function which are automatically generating from the following kinda configuration -
$urls["profile" ] = "http://:username.:host/community";
$urls["avatar" ] = "http://avatar. somewherein. net/avatar/ :username/ for/aawaj";
$urls["logout" ] = "logout";

i am pretty sure you guys are smart enough to figure out how we did that, let me know if you need any help about how we did that.

well first you try yourself and tell me how we did :)

best wishes,
nhm tanveer hossain khan (hasan)
http://hasan. we4tech.com
twit @we4tech
work for fun!





--
Anupom
http://syamantics.com

#12066 From: Anupom <anupom.nsu@...>
Date: Tue May 19, 2009 7:15 am
Subject: Re: [phpXperts] How you manage your url in php application ? (for CodeIgnitor guys)
ae_sumerians98
Offline Offline
Send Email Send Email
 
and this is how I would implement this (without the caching though),

class Url {
  private $urls = array(
    "profile" => "http://<username>.<host>/community",
    "avatar"  => "http://avatar.somewherein.net/avatar/<username>/for/aawaj",
    "logout"  => "http://somewherein.net/logout"
  );

  public function __call($method, $args) {
    $url = $this->urls[$method];
    if(!empty($args[0])) {
      $keys = array_keys($args[0]);
      foreach ($keys as &$key) {
      $key = '<'.$key.'>';
      }
      $url = str_replace($keys, array_values($args[0]), $url);
    }
    if(preg_match('/<([^>]+)>/', $url, $matches)) {
       throw new Exception(
      "Missing key {$matches[0]} in supplied argument for Url::{$method}()"
    );
    }
    return $url;
  }
}

$url = new Url();
echo $url->profile(array("username" => 'somename', "host" => 'somehost'));
echo $url->avatar(array("username" => 'somename'));
echo $url->logout();

thanks,

On Tue, May 19, 2009 at 12:48 PM, Anupom <anupom.nsu@...> wrote:
hi hasan,

i don't know how you guys exactly did this. but i can see the basic idea. i would like to share my 2 cents about your implementation (without seeing it fully anyway),

#1 the profile example ($this->url->profile) should have a 'host' key in your example, it's missing ;) you did not share your implementation but i guess you are handling this issue properly there. if a developer misses a key, then the system should raise an exception immediately. othewise you may end up with a URL like this http://hasan.:host/community. :P

#2. you are using ":" (colon) to determine the word to replace. : is a valid url encoded character and using it this way may lead to some issues later on. like suppose my url pattern is this, $urls["profile"] = "http://:username.:host/community/sortby:username"; in this case the later :username will get replaced too. or you applied some rocket science to avooid this sort of issues?

#3. i hope you are using some sort of caching mechanism in your implementatin. if your page has like > 1000 urls, then these str_replace/preg_replace etc will cost a lot. himel nag rana mentioned this in his mail already. many people had this issue with Rails earlier.

#4. use extensions in url when you are serving static contents (well even if they are dynamically produced). in your case this url does not have any extension - http://avatar.somewherein.net/avatar/:username/for/aawaj. some people may disagree with this by saying 'urls are supposed to identify a resource and not a particular format'. but hey then why don't we get rid of .js and .css extensions? and most servers can automatically determine the MIME type to send in the Content-Type header using the extnsion in the url. also i think it's more semantically correct - a particular resource can have different presentations and they should be determined through the extension, like as in Rails you can serve .xml, .json or .rdf or whatever from a single resource and the format is determined through the extension. also i guess it makes it easy for crawlers to determine the content type of the response.

thanks,


On Tue, May 19, 2009 at 10:07 AM, Himel Nag Rana <h_n_rana@...> wrote:


Dear Hasan Vai,
                          I have a question for you regarding the url issue for codeigniter. 
I got your point of ease of managing urls. The question is regarding performance.
Whenever any url is clicked or hit, the url->profile() function is being called. so for a large site we have to store a large number of url pattern. Is there a chance of performance hampering? Is it possible to use some config constant and call the functions for assigning their values? So that the functions are called only once?

We use routes for url shortening or pattern matching. But haven't use your technique in project till now.

Waiting for you reply.
 
Thanks and Regards ----
Himel Nag Rana
Cell: 01711664049,



From: hasan83bd <hasan83bd@...>
To: phpexperts@yahoogroups.com
Sent: Tuesday, May 19, 2009 1:09:32 AM
Subject: [phpXperts] How you manage your url in php application ? (for CodeIgnitor guys)

Hi,
It has been long while since i last post here in phpexperts group, well i was away from php for pretty long, being more java and ruby on rails guy when i got chance to help few php projects, i borrowed few more neat and nifty design concept from rails to php.

well let me tell you about the story of stories, i ain't treat myself as php expert anymore since being detached or keeping my ass out of it. i'd prefer to call myself as the expert of "work for fun".

before digging into the details let me explain what was wrong and what could be wrong with your current way of using URL through out the php application (web site)

-> Karim, he is given a task to develop a beautiful WOW WOW application in php,

-> He is very WOW WOW developer, develops everything on the fly, produces (TR/Z/B)*illion of bugs on the fly as well.

-> Very promonient developer, he knows how to write php along html, after hearing several good advices he started giving CodeIgnitor a shot.

-> So he used to write the following kinda code in everywhere -

<a href="<?= site_url("user/ profile/10" ) ?>">My profile</a>

Now if you get a chance to look into his view or controller codes, you might see in everywhere he hard coded the url pattern.

what the hell is the URL Pattern?

well, you see "site_url("user/ profile/10" )" this code is expanded to "http://abc.com/user/profile/10" while you execute your code in php. this "user/profile/ :number" is called url pattern.

everywhere in his code base he kept such hard coded url pattern.
let's imagine his client or boss or team lead ask him to change the url pattern "user/profile/ :number" to something similar "profile/:number/ ".

now tell me what would YOU DO? if you were placed in such situation?

well you know if that guy was me, i'd run a string replace command through out the whole project. so wherever i wrote "user/profile/ :number" url pattern that would be converted to "profile/:number"

something like this - /site_url\(" user\/profile\ /(\d+)"\) / replace to site_url("profile/ $1")

well i guess many of you already have such problem with similar solution ;) frankly speaking we had similar problem thus we came up with some solution where we can change URL pattern without modifying existing view or controller code.

here is the evidence -
<a href="<?= $this->url-> profile(array( "username" => $user_profile- >username) ) ?>">
<img src="<?= $this->url-> avatar(array( "username" => $user_profile- >username) ) ?>" />
</a>

you see, we ain't hard coding any url anymore, rather we are calling a function which are automatically generating from the following kinda configuration -
$urls["profile" ] = "http://:username.:host/community";
$urls["avatar" ] = "http://avatar. somewherein. net/avatar/ :username/ for/aawaj";
$urls["logout" ] = "logout";

i am pretty sure you guys are smart enough to figure out how we did that, let me know if you need any help about how we did that.

well first you try yourself and tell me how we did :)

best wishes,
nhm tanveer hossain khan (hasan)
http://hasan. we4tech.com
twit @we4tech
work for fun!





--
Anupom
http://syamantics.com



--
Anupom
http://syamantics.com

#12076 From: "hasan83bd" <hasan83bd@...>
Date: Tue May 19, 2009 5:29 pm
Subject: Re: [phpXperts] How you manage your url in php application ? (for CodeIgnitor guys)
hasan83bd
Offline Offline
Send Email Send Email
 
Hi anupom bhai,
you are absolutely right about it, just here is the complete one with same
request cache and keeping urls mapping in separate configuration file.
very straight forward solution just get it here -
http://hasan.we4tech.com/files/CI-url.zip

best wishes,
nhm tanveer hossain khan (hasan)
http://hasan.we4tech.com
work for fun!

--- In phpexperts@yahoogroups.com, Anupom <anupom.nsu@...> wrote:
>
> and this is how I would implement this (without the caching though),
>
> class Url {
> private $urls = array(
> "profile" => "http://<username>.<host>/community",
> "avatar" => "http://avatar.somewherein.net/avatar/
> <username>/for/aawaj",
> "logout" => "http://somewherein.net/logout"
> );
>
> public function __call($method, $args) {
> $url = $this->urls[$method];
> if(!empty($args[0])) {
> $keys = array_keys($args[0]);
> foreach ($keys as &$key) {
> $key = '<'.$key.'>';
> }
> $url = str_replace($keys, array_values($args[0]), $url);
> }
> if(preg_match('/<([^>]+)>/', $url, $matches)) {
> throw new Exception(
> "Missing key {$matches[0]} in supplied argument for Url::{$method}()"
> );
> }
> return $url;
> }
> }
>
> $url = new Url();
> echo $url->profile(array("username" => 'somename', "host" => 'somehost'));
> echo $url->avatar(array("username" => 'somename'));
> echo $url->logout();
>
> thanks,
>
> On Tue, May 19, 2009 at 12:48 PM, Anupom <anupom.nsu@...> wrote:
>
> > hi hasan,
> >
> > i don't know how you guys exactly did this. but i can see the basic idea. i
> > would like to share my 2 cents about your implementation (without seeing it
> > fully anyway),
> >
> > #1 the profile example ($this->url->profile) should have a 'host' key in
> > your example, it's missing ;) you did not share your implementation but i
> > guess you are handling this issue properly there. if a developer misses a
> > key, then the system should raise an exception immediately. othewise you may
> > end up with a URL like this http://hasan.:host/community. :P
> >
> > #2. you are using ":" (colon) to determine the word to replace. : is a
> > valid url encoded character and using it this way may lead to some issues
> > later on. like suppose my url pattern is this, $urls["profile"] =
"http://:username.:host/community/sortby:username";
> > in this case the later :username will get replaced too. or you applied some
> > rocket science to avooid this sort of issues?
> >
> > #3. i hope you are using some sort of caching mechanism in your
> > implementatin. if your page has like > 1000 urls, then these
> > str_replace/preg_replace etc will cost a lot. himel nag rana mentioned this
> > in his mail already. many people had this issue with Rails earlier.
> >
> > #4. use extensions in url when you are serving static contents (well even
> > if they are dynamically produced). in your case this url does not have any
> > extension - http://avatar.somewherein.net/avatar/:username/for/aawaj. some
> > people may disagree with this by saying 'urls are supposed to identify a
> > resource and not a particular format'. but hey then why don't we get rid of
> > .js and .css extensions? and most servers can automatically determine the
> > MIME type to send in the Content-Type header using the extnsion in the url.
> > also i think it's more semantically correct - a particular resource can have
> > different presentations and they should be determined through the extension,
> > like as in Rails you can serve .xml, .json or .rdf or whatever from a single
> > resource and the format is determined through the extension. also i guess it
> > makes it easy for crawlers to determine the content type of the response.
> >
> > thanks,
> >
> >
> > On Tue, May 19, 2009 at 10:07 AM, Himel Nag Rana <h_n_rana@...>wrote:
> >
> >>
> >>
> >> *Dear Hasan Vai,** I have a question for you
> >> regarding the url issue for codeigniter. *
> >> *I got your point of ease of managing urls. The question is regarding
> >> performance.*
> >> *Whenever any url is clicked or hit, the url->profile() function is being
> >> called. so for a large site we have to store a large number of url pattern.
> >> Is there a chance of performance hampering? Is it possible to use some
> >> config constant and call the functions for assigning their values? So that
> >> the functions are called only once?*
> >> *
> >> *
> >> *We use routes for url shortening or pattern matching. But haven't use
> >> your technique in project till now.*
> >> *
> >> *
> >> *Waiting for you reply.
> >> *
> >> Thanks and Regards ----
> >> Himel Nag Rana
> >> Cell: 01711664049,
> >> Office: http://www.praxisict.com
> >> http://nagbaba.blogspot.com
> >> *http://twitter.com/nagbaba*
> >>
> >>
> >> ------------------------------
> >> *From:* hasan83bd <hasan83bd@...>
> >> *To:* phpexperts@yahoogroups.com
> >> *Sent:* Tuesday, May 19, 2009 1:09:32 AM
> >> *Subject:* [phpXperts] How you manage your url in php application ? (for
> >> CodeIgnitor guys)
> >>
> >> Hi,
> >> It has been long while since i last post here in phpexperts group, well i
> >> was away from php for pretty long, being more java and ruby on rails guy
> >> when i got chance to help few php projects, i borrowed few more neat and
> >> nifty design concept from rails to php.
> >>
> >> well let me tell you about the story of stories, i ain't treat myself as
> >> php expert anymore since being detached or keeping my ass out of it. i'd
> >> prefer to call myself as the expert of "work for fun".
> >>
> >> before digging into the details let me explain what was wrong and what
> >> could be wrong with your current way of using URL through out the php
> >> application (web site)
> >>
> >> -> Karim, he is given a task to develop a beautiful WOW WOW application in
> >> php,
> >>
> >> -> He is very WOW WOW developer, develops everything on the fly, produces
> >> (TR/Z/B)*illion of bugs on the fly as well.
> >>
> >> -> Very promonient developer, he knows how to write php along html, after
> >> hearing several good advices he started giving CodeIgnitor a shot.
> >>
> >> -> So he used to write the following kinda code in everywhere -
> >>
> >> <a href="<?= site_url("user/ profile/10" ) ?>">My profile</a>
> >>
> >> Now if you get a chance to look into his view or controller codes, you
> >> might see in everywhere he hard coded the url pattern.
> >>
> >> what the hell is the URL Pattern?
> >>
> >> well, you see "site_url("user/ profile/10" )" this code is expanded to "
> >> http://abc.com/user/profile/10" while you execute your code in php. this
> >> "user/profile/ :number" is called url pattern.
> >>
> >> everywhere in his code base he kept such hard coded url pattern.
> >> let's imagine his client or boss or team lead ask him to change the url
> >> pattern "user/profile/ :number" to something similar "profile/:number/ ".
> >>
> >> now tell me what would YOU DO? if you were placed in such situation?
> >>
> >> well you know if that guy was me, i'd run a string replace command through
> >> out the whole project. so wherever i wrote "user/profile/ :number" url
> >> pattern that would be converted to "profile/:number"
> >>
> >> something like this - /site_url\(" user\/profile\ /(\d+)"\) / replace to
> >> site_url("profile/ $1")
> >>
> >> well i guess many of you already have such problem with similar solution
> >> ;) frankly speaking we had similar problem thus we came up with some
> >> solution where we can change URL pattern without modifying existing view or
> >> controller code.
> >>
> >> here is the evidence -
> >> <a href="<?= $this->url-> profile(array( "username" => $user_profile-
> >> >username) ) ?>">
> >> <img src="<?= $this->url-> avatar(array( "username" => $user_profile-
> >> >username) ) ?>" />
> >> </a>
> >>
> >> you see, we ain't hard coding any url anymore, rather we are calling a
> >> function which are automatically generating from the following kinda
> >> configuration -
> >> $urls["profile" ] = "http://:username.:host/community";
> >> $urls["avatar" ] = "http://avatar. somewherein. net/avatar/ :username/
> >> for/aawaj <http://avatar.somewherein.net/avatar/:username/for/aawaj>";
> >> $urls["logout" ] = "logout";
> >>
> >> i am pretty sure you guys are smart enough to figure out how we did that,
> >> let me know if you need any help about how we did that.
> >>
> >> well first you try yourself and tell me how we did :)
> >>
> >> best wishes,
> >> nhm tanveer hossain khan (hasan)
> >> http://hasan. we4tech.com <http://hasan.we4tech.com>
> >> twit @we4tech
> >> work for fun!
> >>
> >>
> >>
> >>
> >
> >
> >
> > --
> > Anupom
> > http://syamantics.com
> >
>
>
>
> --
> Anupom
> http://syamantics.com
>





#12077 From: "hasan83bd" <hasan83bd@...>
Date: Tue May 19, 2009 6:00 pm
Subject: Re: [phpXperts] How you manage your url in php application ? (for CodeIgnitor guys)
hasan83bd
Offline Offline
Send Email Send Email
 
Hi,
get my inline comments -

> #1 the profile example ($this->url->profile) should have a 'host' key in
> your example, it's missing ;) you did not share your implementation but i

---> Actually we are taking advantage from base_url (which is defined in CI
configuration) if HOST is explicitly mentioned we override default HOST
(base_url's host).

> guess you are handling this issue properly there. if a developer misses a
> key, then the system should raise an exception immediately. othewise you may
> end up with a URL like this http://hasan.:host/community. :P

---> Our code is not parameter aware though you can implement and contribute
back here :). if you mistype any url name it will raise error.

> #2. you are using ":" (colon) to determine the word to replace. : is a valid
> url encoded character and using it this way may lead to some issues later
> on. like suppose my url pattern is this, $urls["profile"] =
> "http://:username.:host/community/sortby:username";
> in this case the later :username will get replaced too. or you applied some
> rocket science to avooid this sort of issues?

---> You are absolutely right, we ain't have validation check for this, since
you mentioned earlier if we could have parameter check we could eventually get
out of it.

> #3. i hope you are using some sort of caching mechanism in your
> implementatin. if your page has like > 1000 urls, then these
> str_replace/preg_replace etc will cost a lot. himel nag rana mentioned this

---> Yes we have per request cache so if you call an url once on next call it
will hit the cache.

> in his mail already. many people had this issue with Rails earlier.

---> Rails had and tried to tuned a lot, though i like it because of it's
utility. it helps me to not hard code any url.
you know url get changed or you get better fluent pattern to keep in url so you
need to change them. better design it keeping "change" in mind.

> #4. use extensions in url when you are serving static contents (well even if
> they are dynamically produced). in your case this url does not have any
> extension - http://avatar.somewherein.net/avatar/:username/for/aawaj. some
> people may disagree with this by saying 'urls are supposed to identify a
> resource and not a particular format'. but hey then why don't we get rid of
> .js and .css extensions? and most servers can automatically determine the
> MIME type to send in the Content-Type header using the extnsion in the url.
> also i think it's more semantically correct - a particular resource can have
> different presentations and they should be determined through the extension,
> like as in Rails you can serve .xml, .json or .rdf or whatever from a single
> resource and the format is determined through the extension. also i guess it
> makes it easy for crawlers to determine the content type of the response.

---> absolutely agree with you, URL should be reflective. using explicit
resource format it makes cleaner. on that avatar url, we were forwarding to
physical image, thats why we used that for encapsulating url. it other case we
were not serving resources rather we were performing action so no type can be
applicable :)

i think when you need default setup you can use http://abc.com/feed
for more specific type you should explicitly mention format
http://abc.com/feed.atom

> thanks,

---> You are most welcome :)

> On Tue, May 19, 2009 at 10:07 AM, Himel Nag Rana <h_n_rana@...> wrote:
>
> >
> >
> > *Dear Hasan Vai,** I have a question for you
> > regarding the url issue for codeigniter. *
> > *I got your point of ease of managing urls. The question is regarding
> > performance.*
> > *Whenever any url is clicked or hit, the url->profile() function is being
> > called. so for a large site we have to store a large number of url pattern.
> > Is there a chance of performance hampering? Is it possible to use some
> > config constant and call the functions for assigning their values? So that
> > the functions are called only once?*
> > *
> > *
> > *We use routes for url shortening or pattern matching. But haven't use
> > your technique in project till now.*
> > *
> > *
> > *Waiting for you reply.
> > *
> > Thanks and Regards ----
> > Himel Nag Rana
> > Cell: 01711664049,
> > Office: http://www.praxisict.com
> > http://nagbaba.blogspot.com
> > *http://twitter.com/nagbaba*
> >
> >
> > ------------------------------
> > *From:* hasan83bd <hasan83bd@...>
> > *To:* phpexperts@yahoogroups.com
> > *Sent:* Tuesday, May 19, 2009 1:09:32 AM
> > *Subject:* [phpXperts] How you manage your url in php application ? (for
> > CodeIgnitor guys)
> >
> > Hi,
> > It has been long while since i last post here in phpexperts group, well i
> > was away from php for pretty long, being more java and ruby on rails guy
> > when i got chance to help few php projects, i borrowed few more neat and
> > nifty design concept from rails to php.
> >
> > well let me tell you about the story of stories, i ain't treat myself as
> > php expert anymore since being detached or keeping my ass out of it. i'd
> > prefer to call myself as the expert of "work for fun".
> >
> > before digging into the details let me explain what was wrong and what
> > could be wrong with your current way of using URL through out the php
> > application (web site)
> >
> > -> Karim, he is given a task to develop a beautiful WOW WOW application in
> > php,
> >
> > -> He is very WOW WOW developer, develops everything on the fly, produces
> > (TR/Z/B)*illion of bugs on the fly as well.
> >
> > -> Very promonient developer, he knows how to write php along html, after
> > hearing several good advices he started giving CodeIgnitor a shot.
> >
> > -> So he used to write the following kinda code in everywhere -
> >
> > <a href="<?= site_url("user/ profile/10" ) ?>">My profile</a>
> >
> > Now if you get a chance to look into his view or controller codes, you
> > might see in everywhere he hard coded the url pattern.
> >
> > what the hell is the URL Pattern?
> >
> > well, you see "site_url("user/ profile/10" )" this code is expanded to "
> > http://abc.com/user/profile/10" while you execute your code in php. this
> > "user/profile/ :number" is called url pattern.
> >
> > everywhere in his code base he kept such hard coded url pattern.
> > let's imagine his client or boss or team lead ask him to change the url
> > pattern "user/profile/ :number" to something similar "profile/:number/ ".
> >
> > now tell me what would YOU DO? if you were placed in such situation?
> >
> > well you know if that guy was me, i'd run a string replace command through
> > out the whole project. so wherever i wrote "user/profile/ :number" url
> > pattern that would be converted to "profile/:number"
> >
> > something like this - /site_url\(" user\/profile\ /(\d+)"\) / replace to
> > site_url("profile/ $1")
> >
> > well i guess many of you already have such problem with similar solution ;)
> > frankly speaking we had similar problem thus we came up with some solution
> > where we can change URL pattern without modifying existing view or
> > controller code.
> >
> > here is the evidence -
> > <a href="<?= $this->url-> profile(array( "username" => $user_profile-
> > >username) ) ?>">
> > <img src="<?= $this->url-> avatar(array( "username" => $user_profile-
> > >username) ) ?>" />
> > </a>
> >
> > you see, we ain't hard coding any url anymore, rather we are calling a
> > function which are automatically generating from the following kinda
> > configuration -
> > $urls["profile" ] = "http://:username.:host/community";
> > $urls["avatar" ] = "http://avatar. somewherein. net/avatar/ :username/
> > for/aawaj <http://avatar.somewherein.net/avatar/:username/for/aawaj>";
> > $urls["logout" ] = "logout";
> >
> > i am pretty sure you guys are smart enough to figure out how we did that,
> > let me know if you need any help about how we did that.
> >
> > well first you try yourself and tell me how we did :)
> >
> > best wishes,
> > nhm tanveer hossain khan (hasan)
> > http://hasan. we4tech.com <http://hasan.we4tech.com>
> > twit @we4tech
> > work for fun!
> >
> >
> >
> >
>
>
>
> --
> Anupom
> http://syamantics.com
>





#12078 From: "hasan83bd" <hasan83bd@...>
Date: Tue May 19, 2009 5:40 pm
Subject: Re: [phpXperts] How you manage your url in php application ? (for CodeIgnitor guys)
hasan83bd
Offline Offline
Send Email Send Email
 
Hi Rana bhai,
actually this approach is used to adopt alternative approach of not hard coding
any url in php file. so we could change the url pattern without changing the
hard coded php file.

if you call $this->ur->profile(...) several times in a single request the second
call will be delivered from the cache so you don't have to worry that much about
performance.
<?= $this->url->profile(array("username" => "rana")) ?> // Not cached
<?= $this->url->profile(array("username" => "rana")) ?> // Cached

i have replied on anupum bhai's post with our code, still you have enough room
for improvement.

for general clarification -
usually we write -
<a href="/user/<?= $username ?>">user</a>

when you need to change "/user/{name}" to something else you have to replace the
whole code base to replace the similar url patter.

in managed url way -
<a href="<?= $this->url->user(array("user" => $username)) ?>">user</a>

you just have to change url pattern in "application/config/urls.php" not
anywhere else.

best wishes,
--- In phpexperts@yahoogroups.com, Himel Nag Rana <h_n_rana@...> wrote:
>
> Dear Hasan Vai,
> I have a question for you regarding the url issue
for codeigniter.
> I got your point of ease of managing urls. The question is regarding
performance.
> Whenever any url is clicked or hit, the url->profile() function is being
called. so for a large site we have to store a large number of url pattern. Is
there a chance of performance hampering? Is it possible to use some config
constant and call the functions for assigning their values? So that the
functions are called only once?
>
> We use routes for url shortening or pattern matching. But haven't use your
technique in project till now.
>
> Waiting for you reply.
>
>
> Thanks and Regards ----
> Himel Nag Rana
>
> Cell: 01711664049,
> Office: http://www.praxisict.com
>
> http://nagbaba.blogspot.com
> http://twitter.com/nagbaba
>
>
>
>
> ________________________________
> From: hasan83bd <hasan83bd@...>
> To: phpexperts@yahoogroups.com
> Sent: Tuesday, May 19, 2009 1:09:32 AM
> Subject: [phpXperts] How you manage your url in php application ? (for
CodeIgnitor guys)
>
>
>
>
>
> Hi,
> It has been long while since i last post here in phpexperts group, well i was
away from php for pretty long, being more java and ruby on rails guy when i got
chance to help few php projects, i borrowed few more neat and nifty design
concept from rails to php.
>
> well let me tell you about the story of stories, i ain't treat myself as php
expert anymore since being detached or keeping my ass out of it. i'd prefer to
call myself as the expert of "work for fun".
>
> before digging into the details let me explain what was wrong and what could
be wrong with your current way of using URL through out the php application (web
site)
>
> -> Karim, he is given a task to develop a beautiful WOW WOW application in
php,
>
> -> He is very WOW WOW developer, develops everything on the fly, produces
(TR/Z/B)*illion of bugs on the fly as well.
>
> -> Very promonient developer, he knows how to write php along html, after
hearing several good advices he started giving CodeIgnitor a shot.
>
> -> So he used to write the following kinda code in everywhere -
>
> <a href="<?= site_url("user/ profile/10" ) ?>">My profile</a>
>
> Now if you get a chance to look into his view or controller codes, you might
see in everywhere he hard coded the url pattern.
>
> what the hell is the URL Pattern?
>
> well, you see "site_url("user/ profile/10" )" this code is expanded to
"http://abc.com/user/profile/10" while you execute your code in php. this
"user/profile/ :number" is called url pattern.
>
> everywhere in his code base he kept such hard coded url pattern.
> let's imagine his client or boss or team lead ask him to change the url
pattern "user/profile/ :number" to something similar "profile/:number/ ".
>
> now tell me what would YOU DO? if you were placed in such situation?
>
> well you know if that guy was me, i'd run a string replace command through out
the whole project. so wherever i wrote "user/profile/ :number" url pattern that
would be converted to "profile/:number"
>
> something like this - /site_url\(" user\/profile\ /(\d+)"\) / replace to
site_url("profile/ $1")
>
> well i guess many of you already have such problem with similar solution ;)
frankly speaking we had similar problem thus we came up with some solution where
we can change URL pattern without modifying existing view or controller code.
>
> here is the evidence -
> <a href="<?= $this->url-> profile(array( "username" => $user_profile-
>username) ) ?>">
> <img src="<?= $this->url-> avatar(array( "username" => $user_profile-
>username) ) ?>" />
> </a>
>
> you see, we ain't hard coding any url anymore, rather we are calling a
function which are automatically generating from the following kinda
configuration -
> $urls["profile" ] = "http://:username.:host/community";
> $urls["avatar" ] = "http://avatar. somewherein. net/avatar/ :username/
for/aawaj";
> $urls["logout" ] = "logout";
>
> i am pretty sure you guys are smart enough to figure out how we did that, let
me know if you need any help about how we did that.
>
> well first you try yourself and tell me how we did :)
>
> best wishes,
> nhm tanveer hossain khan (hasan)
> http://hasan. we4tech.com
> twit @we4tech
> work for fun!
>





#12080 From: Himel Nag Rana <h_n_rana@...>
Date: Tue May 19, 2009 6:46 pm
Subject: Re: [phpXperts] How you manage your url in php application ? (for CodeIgnitor guys)
h_n_rana
Online Now Online Now
Send Email Send Email
 
Dear hasan vai, 
                            I got your point regarding performance. That sounds good. For URL pattern recognition we are currently using routes.php configs and with slight modification in the router library class in CI. Your and Anupom vai's solution will let us play with urls in more dynamic way.

 
Thanks and Regards ----
Himel Nag Rana
Praxis ICT Ltd,
Cell: 01711664049,



From: hasan83bd <hasan83bd@...>
To: phpexperts@yahoogroups.com
Sent: Tuesday, May 19, 2009 11:40:51 PM
Subject: Re: [phpXperts] How you manage your url in php application ? (for CodeIgnitor guys)

Hi Rana bhai,
actually this approach is used to adopt alternative approach of not hard coding any url in php file. so we could change the url pattern without changing the hard coded php file.

if you call $this->ur->profile( ...) several times in a single request the second call will be delivered from the cache so you don't have to worry that much about performance.
<?= $this->url-> profile(array( "username" => "rana")) ?> // Not cached
<?= $this->url-> profile(array( "username" => "rana")) ?> // Cached

i have replied on anupum bhai's post with our code, still you have enough room for improvement.

for general clarification -
usually we write -
<a href="/user/ <?= $username ?>">user</a>

when you need to change "/user/{name} " to something else you have to replace the whole code base to replace the similar url patter.

in managed url way -
<a href="<?= $this->url-> user(array( "user" => $username)) ?>">user</a>

you just have to change url pattern in "application/ config/urls. php" not anywhere else.

best wishes,
--- In phpexperts@yahoogro ups.com, Himel Nag Rana <h_n_rana@.. .> wrote:
>
> Dear Hasan Vai,
> I have a question for you regarding the url issue for codeigniter.
> I got your point of ease of managing urls. The question is regarding performance.
> Whenever any url is clicked or hit, the url->profile( ) function is being called. so for a large site we have to store a large number of url pattern. Is there a chance of performance hampering? Is it possible to use some config constant and call the functions for assigning their values? So that the functions are called only once?
>
> We use routes for url shortening or pattern matching. But haven't use your technique in project till now.
>
> Waiting for you reply.
>
>
> Thanks and Regards ----
> Himel Nag Rana
>
> Cell: 01711664049,
> Office: http://www.praxisict.com
>
> http://nagbaba. blogspot. com
> http://twitter. com/nagbaba
>
>
>
>
> ____________ _________ _________ __
> From: hasan83bd <hasan83bd@. ..>
> To: phpexperts@yahoogro ups.com
> Sent: Tuesday, May 19, 2009 1:09:32 AM
> Subject: [phpXperts] How you manage your url in php application ? (for CodeIgnitor guys)
>
>
>
>
>
> Hi,
> It has been long while since i last post here in phpexperts group, well i was away from php for pretty long, being more java and ruby on rails guy when i got chance to help few php projects, i borrowed few more neat and nifty design concept from rails to php.
>
> well let me tell you about the story of stories, i ain't treat myself as php expert anymore since being detached or keeping my ass out of it. i'd prefer to call myself as the expert of "work for fun".
>
> before digging into the details let me explain what was wrong and what could be wrong with your current way of using URL through out the php application (web site)
>
> -> Karim, he is given a task to develop a beautiful WOW WOW application in php,
>
> -> He is very WOW WOW developer, develops everything on the fly, produces (TR/Z/B)*illion of bugs on the fly as well.
>
> -> Very promonient developer, he knows how to write php along html, after hearing several good advices he started giving CodeIgnitor a shot.
>
> -> So he used to write the following kinda code in everywhere -
>
> <a href="<?= site_url("user/ profile/10" ) ?>">My profile</a>
>
> Now if you get a chance to look into his view or controller codes, you might see in everywhere he hard coded the url pattern.
>
> what the hell is the URL Pattern?
>
> well, you see "site_url("user/ profile/10" )" this code is expanded to "http://abc.com/user/profile/10" while you execute your code in php. this "user/profile/ :number" is called url pattern.
>
> everywhere in his code base he kept such hard coded url pattern.
> let's imagine his client or boss or team lead ask him to change the url pattern "user/profile/ :number" to something similar "profile/:number/ ".
>
> now tell me what would YOU DO? if you were placed in such situation?
>
> well you know if that guy was me, i'd run a string replace command through out the whole project. so wherever i wrote "user/profile/ :number" url pattern that would be converted to "profile/:number"
>
> something like this - /site_url\(" user\/profile\ /(\d+)"\) / replace to site_url("profile/ $1")
>
> well i guess many of you already have such problem with similar solution ;) frankly speaking we had similar problem thus we came up with some solution where we can change URL pattern without modifying existing view or controller code.
>
> here is the evidence -
> <a href="<?= $this->url-> profile(array( "username" => $user_profile- >username) ) ?>">
> <img src="<?= $this->url-> avatar(array( "username" => $user_profile- >username) ) ?>" />
> </a>
>
> you see, we ain't hard coding any url anymore, rather we are calling a function which are automatically generating from the following kinda configuration -
> $urls["profile" ] = "http://:username.:host/community";
> $urls["avatar" ] = "http://avatar. somewherein. net/avatar/ :username/ for/aawaj";
> $urls["logout" ] = "logout";
>
> i am pretty sure you guys are smart enough to figure out how we did that, let me know if you need any help about how we did that.
>
> well first you try yourself and tell me how we did :)
>
> best wishes,
> nhm tanveer hossain khan (hasan)
> http://hasan. we4tech.com
> twit @we4tech
> work for fun!
>



#12116 From: Anupom <anupom.nsu@...>
Date: Fri May 22, 2009 4:58 pm
Subject: Re: [phpXperts] How you manage your url in php application ? (for CodeIgnitor guys)
ae_sumerians98
Offline Offline
Send Email Send Email
 
sorry for the late reply. thanks a lot Hasan for raising this up, it's ofcourse a very handy and life saving feature.
change is the rule of the web universe and we should always (atleast try to) "design for change". change is inevitable here :)

thanks Anis, beside ZF, it is already implemented in CakePHP and Kohana Framework as well and is called reverse routing.

the implementation is a bit different though. to make use of this feature in CakePHP we need to use the $html->link() method like the following,

$html->link('User Profile', array(
         'controller' => 'users',
         'action' => 'profile',
         999
      ));

instead of plain and simple, $html->link('User Profile', '/users/profile/5')

certainly the new one is much much more verbose than the old one. but the BIG advantage is that now if we need to change the URL pattern then we just have to edit in only one single place.

as an example, if in some point of our development, we decide to change the pattern of the URL to an user's profile to profile/* instead of user/profile/* we just have to make a little change in the router and it's done,

Router::connect('/profile/*', array('controller' => 'users', 'action' => 'profile'));

thanks

On Wed, May 20, 2009 at 12:46 AM, Himel Nag Rana <h_n_rana@...> wrote:


Dear hasan vai, 
                            I got your point regarding performance. That sounds good. For URL pattern recognition we are currently using routes.php configs and with slight modification in the router library class in CI. Your and Anupom vai's solution will let us play with urls in more dynamic way.

 
Thanks and Regards ----
Himel Nag Rana
Praxis ICT Ltd,



From: hasan83bd <hasan83bd@...>
To: phpexperts@yahoogroups.com
Sent: Tuesday, May 19, 2009 11:40:51 PM
Subject: Re: [phpXperts] How you manage your url in php application ? (for CodeIgnitor guys)

Hi Rana bhai,
actually this approach is used to adopt alternative approach of not hard coding any url in php file. so we could change the url pattern without changing the hard coded php file.

if you call $this->ur->profile( ...) several times in a single request the second call will be delivered from the cache so you don't have to worry that much about performance.
<?= $this->url-> profile(array( "username" => "rana")) ?> // Not cached
<?= $this->url-> profile(array( "username" => "rana")) ?> // Cached

i have replied on anupum bhai's post with our code, still you have enough room for improvement.

for general clarification -
usually we write -
<a href="/user/ <?= $username ?>">user</a>

when you need to change "/user/{name} " to something else you have to replace the whole code base to replace the similar url patter.

in managed url way -
<a href="<?= $this->url-> user(array( "user" => $username)) ?>">user</a>

you just have to change url pattern in "application/ config/urls. php" not anywhere else.

best wishes,
--- In phpexperts@yahoogro ups.com, Himel Nag Rana <h_n_rana@.. .> wrote:
>
> Dear Hasan Vai,
> I have a question for you regarding the url issue for codeigniter.
> I got your point of ease of managing urls. The question is regarding performance.
> Whenever any url is clicked or hit, the url->profile( ) function is being called. so for a large site we have to store a large number of url pattern. Is there a chance of performance hampering? Is it possible to use some config constant and call the functions for assigning their values? So that the functions are called only once?
>
> We use routes for url shortening or pattern matching. But haven't use your technique in project till now.
>
> Waiting for you reply.
>
>
> Thanks and Regards ----
> Himel Nag Rana
>
> Cell: 01711664049,
> Office: http://www.praxisict.com
>
> http://nagbaba. blogspot. com
> http://twitter. com/nagbaba
>
>
>
>
> ____________ _________ _________ __
> From: hasan83bd <hasan83bd@. ..>
> To: phpexperts@yahoogro ups.com

> Sent: Tuesday, May 19, 2009 1:09:32 AM
> Subject: [phpXperts] How you manage your url in php application ? (for CodeIgnitor guys)
>
>
>
>
>
> Hi,
> It has been long while since i last post here in phpexperts group, well i was away from php for pretty long, being more java and ruby on rails guy when i got chance to help few php projects, i borrowed few more neat and nifty design concept from rails to php.
>
> well let me tell you about the story of stories, i ain't treat myself as php expert anymore since being detached or keeping my ass out of it. i'd prefer to call myself as the expert of "work for fun".
>
> before digging into the details let me explain what was wrong and what could be wrong with your current way of using URL through out the php application (web site)
>
> -> Karim, he is given a task to develop a beautiful WOW WOW application in php,
>
> -> He is very WOW WOW developer, develops everything on the fly, produces (TR/Z/B)*illion of bugs on the fly as well.
>
> -> Very promonient developer, he knows how to write php along html, after hearing several good advices he started giving CodeIgnitor a shot.
>
> -> So he used to write the following kinda code in everywhere -
>
> <a href="<?= site_url("user/ profile/10" ) ?>">My profile</a>
>
> Now if you get a chance to look into his view or controller codes, you might see in everywhere he hard coded the url pattern.
>
> what the hell is the URL Pattern?
>
> well, you see "site_url("user/ profile/10" )" this code is expanded to "http://abc.com/user/profile/10" while you execute your code in php. this "user/profile/ :number" is called url pattern.
>
> everywhere in his code base he kept such hard coded url pattern.
> let's imagine his client or boss or team lead ask him to change the url pattern "user/profile/ :number" to something similar "profile/:number/ ".
>
> now tell me what would YOU DO? if you were placed in such situation?
>
> well you know if that guy was me, i'd run a string replace command through out the whole project. so wherever i wrote "user/profile/ :number" url pattern that would be converted to "profile/:number"
>
> something like this - /site_url\(" user\/profile\ /(\d+)"\) / replace to site_url("profile/ $1")
>
> well i guess many of you already have such problem with similar solution ;) frankly speaking we had similar problem thus we came up with some solution where we can change URL pattern without modifying existing view or controller code.
>
> here is the evidence -
> <a href="<?= $this->url-> profile(array( "username" => $user_profile- >username) ) ?>">
> <img src="<?= $this->url-> avatar(array( "username" => $user_profile- >username) ) ?>" />
> </a>
>
> you see, we ain't hard coding any url anymore, rather we are calling a function which are automatically generating from the following kinda configuration -
> $urls["profile" ] = "http://:username.:host/community";
> $urls["avatar" ] = "http://avatar. somewherein. net/avatar/ :username/ for/aawaj";
> $urls["logout" ] = "logout";
>
> i am pretty sure you guys are smart enough to figure out how we did that, let me know if you need any help about how we did that.
>
> well first you try yourself and tell me how we did :)
>
> best wishes,
> nhm tanveer hossain khan (hasan)
> http://hasan. we4tech.com
> twit @we4tech
> work for fun!
>





--
Anupom
http://syamantics.com

#12072 From: "Anis Ahmad" <anisniit@...>
Date: Tue May 19, 2009 10:26 am
Subject: Re: How you manage your url in php application ? (for CodeIgnitor guys)
anis_niit
Offline Offline
Send Email Send Email
 
Dear Hasan vai,

Thanks a lot for your great post. URL patterns surely can help us for building
dynamic, hackable and SEO friendly URLs.

BTW, URL pattern is not a new concept in PHP.
I've already used this at least 2 of my previous projects which were build on
Zend Framework.

http://framework.zend.com/manual/en/zend.controller.router.html

But CI doesn't have any built-in interface for this. Hope, Anupom vai's class
may help us for this purpose. (Thanks Anupom vai)

@Anupom vai
If u can manage time, u can make a helper of CI for using URL Patterns. Lots of
CI devs will be benefited.

Thanks and Regards
---
Anis uddin Ahmad
Right Brain Solution Ltd.
http://ajaxray.com

--- In phpexperts@yahoogroups.com, "hasan83bd" <hasan83bd@...> wrote:
>
> Hi,
> It has been long while since i last post here in phpexperts group, well i was
away from php for pretty long, being more java and ruby on rails guy when i got
chance to help few php projects, i borrowed few more neat and nifty design
concept from rails to php.
>
> well let me tell you about the story of stories, i ain't treat myself as php
expert anymore since being detached or keeping my ass out of it. i'd prefer to
call myself as the expert of "work for fun".
>
> before digging into the details let me explain what was wrong and what could
be wrong with your current way of using URL through out the php application (web
site)
>
> -> Karim, he is given a task to develop a beautiful WOW WOW application in
php,
>
> -> He is very WOW WOW developer, develops everything on the fly, produces
(TR/Z/B)*illion of bugs on the fly as well.
>
> -> Very promonient developer, he knows how to write php along html, after
hearing several good advices he started giving CodeIgnitor a shot.
>
> -> So he used to write the following kinda code in everywhere -
>
> <a href="<?= site_url("user/profile/10") ?>">My profile</a>
>
> Now if you get a chance to look into his view or controller codes, you might
see in everywhere he hard coded the url pattern.
>
> what the hell is the URL Pattern?
>
> well, you see "site_url("user/profile/10")" this code is expanded to
"http://abc.com/user/profile/10" while you execute your code in php. this
"user/profile/:number" is called url pattern.
>
> everywhere in his code base he kept such hard coded url pattern.
> let's imagine his client or boss or team lead ask him to change the url
pattern "user/profile/:number" to something similar "profile/:number/".
>
> now tell me what would YOU DO? if you were placed in such situation?
>
> well you know if that guy was me, i'd run a string replace command through out
the whole project. so wherever i wrote "user/profile/:number" url pattern that
would be converted to "profile/:number"
>
> something like this - /site_url\("user\/profile\/(\d+)"\)/ replace to
site_url("profile/$1")
>
>
> well i guess many of you already have such problem with similar solution ;)
frankly speaking we had similar problem thus we came up with some solution where
we can change URL pattern without modifying existing view or controller code.
>
> here is the evidence -
> <a href="<?= $this->url->profile(array("username" => $user_profile->username))
?>">
> <img src="<?= $this->url->avatar(array("username" => $user_profile->username))
?>" />
> </a>
>
> you see, we ain't hard coding any url anymore, rather we are calling a
function which are automatically generating from the following kinda
configuration -
> $urls["profile"] = "http://:username.:host/community";
> $urls["avatar"] = "http://avatar.somewherein.net/avatar/:username/for/aawaj";
> $urls["logout"] = "logout";
>
> i am pretty sure you guys are smart enough to figure out how we did that, let
me know if you need any help about how we did that.
>
> well first you try yourself and tell me how we did :)
>
> best wishes,
> nhm tanveer hossain khan (hasan)
> http://hasan.we4tech.com
> twit @we4tech
> work for fun!
>





#12079 From: "hasan83bd" <hasan83bd@...>
Date: Tue May 19, 2009 6:13 pm
Subject: Re: How you manage your url in php application ? (for CodeIgnitor guys)
hasan83bd
Offline Offline
Send Email Send Email
 
> BTW, URL pattern is not a new concept in PHP.
> I've already used this at least 2 of my previous projects which were build on
Zend Framework.
>
> http://framework.zend.com/manual/en/zend.controller.router.html

---> This is absolutely right, though Zend framework looks to me exposing over
object orientation. unnecessary class!.

$router = $ctrl->getRouter();
$router->addRoute(
'user',
new Zend_Controller_Router_Route('user/:username',
array('controller' => 'user',
'action' => 'info'))
);

i am not getting impressed by looking at this overwhelming code ;)
here is our similar code -

$urls["profile_url"] = "user/:username";

> But CI doesn't have any built-in interface for this. Hope, Anupom vai's class
may help us for this purpose. (Thanks Anupom vai)
>
> @Anupom vai
> If u can manage time, u can make a helper of CI for using URL Patterns. Lots
of CI devs will be benefited.
>
> Thanks and Regards
> ---
> Anis uddin Ahmad
> Right Brain Solution Ltd.
> http://ajaxray.com
>
> --- In phpexperts@yahoogroups.com, "hasan83bd" <hasan83bd@> wrote:
> >
> > Hi,
> > It has been long while since i last post here in phpexperts group, well i
was away from php for pretty long, being more java and ruby on rails guy when i
got chance to help few php projects, i borrowed few more neat and nifty design
concept from rails to php.
> >
> > well let me tell you about the story of stories, i ain't treat myself as php
expert anymore since being detached or keeping my ass out of it. i'd prefer to
call myself as the expert of "work for fun".
> >
> > before digging into the details let me explain what was wrong and what could
be wrong with your current way of using URL through out the php application (web
site)
> >
> > -> Karim, he is given a task to develop a beautiful WOW WOW application in
php,
> >
> > -> He is very WOW WOW developer, develops everything on the fly, produces
(TR/Z/B)*illion of bugs on the fly as well.
> >
> > -> Very promonient developer, he knows how to write php along html, after
hearing several good advices he started giving CodeIgnitor a shot.
> >
> > -> So he used to write the following kinda code in everywhere -
> >
> > <a href="<?= site_url("user/profile/10") ?>">My profile</a>
> >
> > Now if you get a chance to look into his view or controller codes, you might
see in everywhere he hard coded the url pattern.
> >
> > what the hell is the URL Pattern?
> >
> > well, you see "site_url("user/profile/10")" this code is expanded to
"http://abc.com/user/profile/10" while you execute your code in php. this
"user/profile/:number" is called url pattern.
> >
> > everywhere in his code base he kept such hard coded url pattern.
> > let's imagine his client or boss or team lead ask him to change the url
pattern "user/profile/:number" to something similar "profile/:number/".
> >
> > now tell me what would YOU DO? if you were placed in such situation?
> >
> > well you know if that guy was me, i'd run a string replace command through
out the whole project. so wherever i wrote "user/profile/:number" url pattern
that would be converted to "profile/:number"
> >
> > something like this - /site_url\("user\/profile\/(\d+)"\)/ replace to
site_url("profile/$1")
> >
> >
> > well i guess many of you already have such problem with similar solution ;)
frankly speaking we had similar problem thus we came up with some solution where
we can change URL pattern without modifying existing view or controller code.
> >
> > here is the evidence -
> > <a href="<?= $this->url->profile(array("username" =>
$user_profile->username)) ?>">
> > <img src="<?= $this->url->avatar(array("username" =>
$user_profile->username)) ?>" />
> > </a>
> >
> > you see, we ain't hard coding any url anymore, rather we are calling a
function which are automatically generating from the following kinda
configuration -
> > $urls["profile"] = "http://:username.:host/community";
> > $urls["avatar"] =
"http://avatar.somewherein.net/avatar/:username/for/aawaj";
> > $urls["logout"] = "logout";
> >
> > i am pretty sure you guys are smart enough to figure out how we did that,
let me know if you need any help about how we did that.
> >
> > well first you try yourself and tell me how we did :)
> >
> > best wishes,
> > nhm tanveer hossain khan (hasan)
> > http://hasan.we4tech.com
> > twit @we4tech
> > work for fun!
> >
>





 
Advanced
Add to My Yahoo!      XML What's This?

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help