Hi peeps,I have mush trouble in creating a user with a unique
profile.In particular i have created the relations between the 2
tables (user,profiles) and then i wanted to put some crud
functionality in each one.The crud for user is working well,but i am
facing problems with the profile's crud.First of all,i want to make an
association from user to profile with the user_id but i cant pass it
to profile.Moreover,i want to create an addition relation with the
profile_id to the user so that the user can only make 1 profile.
To help you understand i have troubles in add,and edit functions of
the profiles_controller.Can you give me a solution?
Here is my code:

views/profiles/add.ctp

<h1>User Profile</h1>


<?php echo $form->create('Profile',array('url'=>array
('controller'=>'profiles','action'=>'add')));?>


<fieldset>

        <?php echo $form->hidden('Profile.user_id', array
( 'value'=>'$user_id')); ?>

        <?php echo $form->input ('Profile.name', array ('class'=>
 'fullwidth', 'label'=> 'Firstname:'));?>

        <?php echo $form->input ('Profile.lastname', array ('class'=>
 'fullwidth', 'label'=> 'Lastname:'));?>

        <?php echo $form->input ('Profile.dateBirth', array
 ('class'=> 'fullwidth', 'label'=> 'Birth Date:'));?>

        <?php echo $form->input ('Profile.address', array ('class'=>
 'fullwidth', 'label'=> 'Address:')); ?>

        <?php echo $form->input ('Profile.city', array ('class'=>
 'fullwidth', 'label'=> 'City:')); ?>

                <?php echo $form->input ('Profile.town', array ('class'=>
 'fullwidth', 'label'=> 'Town:')); ?>

        <?php echo $form->input ('Profile.number', array ('class'=>
 'fullwidth','label'=> 'Number:')); ?>



</fieldset>
<br>

         <?php echo ($form->submit('Create', array('div' =>
false,'class' => 'submitbutton'))); ?>
 <?php echo($form->end()); ?>


controllers/users_controller

<?php
class UsersController extends AppController {
        var $name = 'Users';
        var $helpers = array('Html', 'Form' );
        var $uses = array('User', 'Profile');

        function index() {
        $this->set('users', $this->User->find('all'));
     }
function view($id = null){
                $this->User->id = $id;
        $this->set('user', $this->User->read());
        }


        function add() {
                if (!empty($this->data)) {
                        if      ($this->User->save($this->data)){
                                $this->Session->setflash('The User has been 
saved.');
                                $this->redirect(array('action' => 'index'));
                                }

                }
        }

        function delete($id) {
                $this->User->del($id);
                $this->Session->setflash('The User with id: '.$id.' has been
deleted.');
                $this->redirect('/users');
        }


        function edit($id = null) {
                $this->User->id = $id;
                if (empty($this->data)) {
                        $this->data = $this->User->read();
                } else {
                        if ($this->User->save($this->data)) {
                        $this->Session->setflash('Your personal details have 
been
updated!');
                        $this->redirect('/users');
                        }
                }
        }

}
?>


controllers/profiles_controller

<?php
class ProfilesController extends AppController {
        var $name = 'Profiles';
        var $helpers = array('Html', 'Form' );
        var $uses = array('User', 'Profile');
function add() {
                if (!empty($this->data)) {
                        $user = $this->User->save($this->data);
                        if(!empty($user)){
                                $this->data['Profile']['user_id'] = 
$this->User->id;
                                $this->User->Profile->save($this->data);
                                $this->data['User']['profile_id'] = 
$this->User->Profile->id;
                                $this->User->save($this->data);
                                $this->redirect('/users');

                }
                }
        }
function view($id = null){
        $this->Profile->id = $id;
        $this->set('profile', $this->Profile->read());
    }

        function edit($id = null) {
                $this->Profile->id = $id;
                if (empty($this->data)) {
                        $this->data = $this->Profile->read();
                } else {
                        if ($this->User->Profile->save($this->data)) {
                        $this->Session->setflash('Your profile details have been
updated!');
                        $this->redirect('/users');
                        }
                }

        }
        function delete($id) {
                $this->Profile->del($id);
                $this->Session->setflash('The Profile with id: '.$id.' has been
deleted.');
                $this->redirect('/users');
        }
}
?>

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