I agree with you. It seems the post.id will be better than a none friendly URL in my case. I will choose the other way to implement this and it really wast me a lot of time. Robert, thanks for your suggestion.
On Wed, Aug 12, 2009 at 9:44 PM, Robert P <[email protected]> wrote: > > If a character is not URL-friendly without being encoded, then in my > mind it serves no purpose in a clean URL. If you are running an > internationalised multi-lingual website then is it not feasible to > rely on something other than a localised URL segment to serve the > content? > > Surely something like /tw/posts/view/whats-the-project-name-is or > even /posts/view/whats-the-project-name-is/lang:tw is better than > turning the address bar to localised gibberish. > > On Aug 12, 8:44 pm, joshua <[email protected]> wrote: > > I got what you say. Consider multi-language case. > > For English, I use following code to make the friendly url > > [code] > > $string = strtolower($string); > > // Any non valid characters will be treated as _, also remove > > duplicate _ > > $string = preg_replace('/[^a-z0-9_]/i', '-', $string); > > $string = preg_replace('/_[_]*/i', '-', $string); > > // Cut at a specified length > > if (strlen($string) > $currentMaximumURLLength){ > > $string = substr($string, 0, $currentMaximumURLLength); > > } > > // Remove beggining and ending signs > > $string = preg_replace('/_$/i', '', $string); > > $string = preg_replace('/^_/i', '', $string); > > > > return $string; > > [/code] > > > > But for none English language, for example, in Chinese. I should encode > the > > url firstly. > > Addslashes is not nessary, you can consider just urlencode case. > > > > [code] > > $url = urlencode($url); > > //$url='what%26%23039%3Bs+the+project+name+is%3F' > > [/code] > > > > > > > > On Wed, Aug 12, 2009 at 8:32 PM, Robert P <[email protected]> > wrote: > > > > > That URL looks extremely unfriendly to me. I can understand urlencode > > > (), but why addslashes() as well? > > > > > This has been covered many, many, many times before. For friendly & > > > clean URLs use: > > > Inflector::slug($url, '-'); > > > > > On Aug 12, 8:17 pm, joshua <[email protected]> wrote: > > > > I want to make a friendly url in my app. > > > > So assume the url likes following: > > > > [code] > > > > var $url = "what's the project name is?"; > > > > [/code] > > > > > > Before I insert this url into database, I want to encode it firstly. > > > > [code] > > > > $url = urlencode(addslashes($url)); //$url > > > > ='what%26%23039%3Bs+the+project+name+is%3F' > > > > [/code] > > > > > > So in the post list view, the post link looks like: > > > > [url] > > >http://www.example.com/posts/view/what%26%23039%3Bs+the+project+name+. > .. > > > > [/url] > > > > > > But when I try to get the parameter in post controller, it print > 'what', > > > not > > > > the whole string('what%26%23039%3Bs+the+project+name+is%3F'). > > > > > > PostsController: > > > > [code] > > > > function view($url){ > > > > debug($url);// print out "what"} > > > > > > [/code] > > > > As you can see the strng after 'what' was cut off. Is there any way > that > > > I > > > > can get the whole parameter in post controller? > > > > Thanks in advance! :-] > > > > > > Joshua > > > > 5span.com <https://www.5span.com> > > > > -- > > Thanks > > Joshua > > > -- Thanks Joshua 5span.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
