Hi ppl,
I have 2 tables users and profiles.I have set the associations and
everything works fine.I use auth.user.id to pass the user_id and i
have a user with his profile then.Now i want to check if the profile
exists and to show a message to the user that "Profile already exists"
when he pushes the add profile button.I am doing this but it always
tell me that profile exists.

Code:
function add($id=null){
                $this->layout = 'add_profile';

                if ($this->data['Profile']['name'] != NULL) {
                        $this->Session->setflash('Profile already exists.');

                } else {
                $user_id = $this->Session->read('Auth.User.id');
                if (!empty($this->data['Profile'])) {
               $this->data['Profile']['class'] = 'User';
               $this->data['Profile']['user_id'] = $user_id;
               $this->User->Profile->create();
                      if ($this->User->Profile->save($this->data)) {
                               $this->Session->setflash('Profile has
been saved.');
                                $this->redirect('/users');
                       }
                       $this->Session->setflash('Profile cannot be
saved.Please, try again.');

        }
                $user = $this->User->read(null, $id);
                        $this->set(compact('user'));
         }
    }

As you see i check if the name field is null and if it is the
procedure is known.
Also i want to do something similar for the delete action. e.g if
there is not a profile to delete just warn the user with a message.

any help would be appreciated!!!
--~--~---------~--~----~------------~-------~--~----~
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