Quantcast

Two different urls parameters for the same page ?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Two different urls parameters for the same page ?

JonStark
Hello everyone,

I have a simple question :

In my app, I use router + controller to get url like this :

/profile/HASH ( myapp.com/profile/hgv5435634vfhcfg6YVC4 )


Routes :

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

Controller :

public function view($id) {
    $user = $this->User->find('first', array(
    'conditions' => array('User.hash' => $id),
    ));
    $this->set(compact('user'));
    }

In my users database, I have hash and username fields.

The hash is used to get data from another website from a user's email.

But I want users to be able to get their profile from 

 /profile/username ( myapp.com/profile/username )

too.

How is this achievable ?

Thanks a lot for your time.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Two different urls parameters for the same page ?

JonStark
Ok, self-RTM :

this works :

    public function view($id) {
    $user = $this->User->find('first', array(
    'conditions' => array(
    "or" => array(
    'User.hash' => $id,
    'User.username' => $id
    )
    ),
    ));
    $this->set(compact('user'));
    }


Le mercredi 9 mai 2012 12:50:16 UTC+2, JonStark a écrit :
Hello everyone,

I have a simple question :

In my app, I use router + controller to get url like this :



Routes :

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

Controller :

public function view($id) {
    $user = $this->User->find('first', array(
    'conditions' => array('User.hash' => $id),
    ));
    $this->set(compact('user'));
    }

In my users database, I have hash and username fields.

The hash is used to get data from another website from a user's email.

But I want users to be able to get their profile from 

 /profile/username ( myapp.com/profile/username )

too.

How is this achievable ?

Thanks a lot for your time.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Loading...