I have a users table and would like to view my users by username with
a url like example.com/users/view/username
In order to do that I have set my view function in my users controller
to
function view($username) {
                if (!$username) {
                        $this->Session->setFlash(__('Invalid User.', true));
                        $this->redirect('/pages/error');
                        exit();
                }
                if ($user = $this->User->findByUsername($username)) {
                        $this->set('user', $user);
                }
                if ($this->Auth->user('role') == 'admin') {
                        // $this->flash('You have admin access');
                        $this->Session->setFlash(__('You have admin access', 
true));
                }
        }

While this will work correctly, showing an existing users profile it
fails to redirect to an error page when you replace the username with
one that doesn't exist. As I was looking for an answer to this I found
a few articles that state I should always set my function view to $id
then rewrite the url to contain the username.

I was wondering if there was a best practice to follow or if what I am
doing is okay?
Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to