It works for me. What's needed, though, is a regexp and then rules to
ensure that the user-defined slug will match when it's created.

/* matches underscore, hyphen, and lowercase alpha
 */
Router::connect('/users/:user_slug',
        array('controller' => 'users', 'action' => 'view'),
        array('user_slug' => '[-_a-z]+')
);

Router::connect('/users/:user_id',
        array('controller' => 'users', 'action' => 'view'),
        array('user_id' => '[0-9]+')
);

Then, in the controller:

function view($id = null)
{
    if (empty($id))
    {
         if (isset($this->params['user_slug']))
         {
               /* either find the user or the user id from the slug,
whichever is preferred
                */
               $this->set('user',
$this->User->findBySlug($this->param['user_slug']));
          }
          else if (isset($this->params['user_id']))
          {
               // ...
          }
          else
          {
                // error
           }
      }
      else
      {
            // find by ID
       }
}

On Thu, Jun 12, 2008 at 3:41 PM, Jonathan Snook
<[EMAIL PROTECTED]> wrote:
>
> On Thu, Jun 12, 2008 at 12:52 PM, mwcbrent <[EMAIL PROTECTED]> wrote:
>> I'm looking to setup a system that will do rewrites, this is
>> similar to myspace or other sites that allow you to setup a page and
>> change the url to something personalized.
>> www.mysite.com/user/232434
>> to
>> www.mysite.com/user/myhomepage
>
> Reusing /user/* for both IDs and custom labels is going to be a pain.
> I'd recommend coming up with something different for the /user/ part
> to more readily differentiate between the two structures. For example:
>
> Router::connect('/person/:label', array('controller'=>'users',
> 'action'=>'bylabel'), array('label'=>'.*')); (or something like that)
>
> function bylabel(){
>      $user = $this->User->findByLabel($this->params['label']);
>      [...other code here...]
> }
>
> That's a pretty rough idea.
>
>> Is there a way to get the routing system to check the database?  Or
>> should i just not even use the routing system and query the db with
>> 'myhomepage' instead of the user id passed in the url?
>>
>> Thanks for the feedback.
>>
>> >
>>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to