Rss Feed
  1. I have Profile table in this registering user details will save and User table where credentials will save..
    To make define Model in User as

    var $hasOne = array(
    'Profile' => array(
    'className' => ' Profile ',
    'foreignKey' => ' profile_id',
     'dependent'    => true
    )
    );

        and in Profile model add

     var $belongsTo = array(
     'User' => array(
    'className' => 'User',
    'foreignKey' => 'user_id',
    'conditions' => '',
    'fields' => '',
    'order' => ''
    )
    );


    In user_controller add

     function addmerchant() {
            {   
                if(!empty($this->data))
                 {  
                    $this->User->create();
    $this->data['User']['role_id'] = 4; // Registered
    $this->data['User']['activation_key'] = md5(uniqid());
    $this->data['User']['status'] = 0;
    $this->data['User']['username'] = htmlspecialchars($this->data['User']['username']);
    $this->data['User']['website'] = htmlspecialchars($this->data['User']['website']);
    $this->data['User']['name'] = htmlspecialchars($this->data['User']['name']); // assigning form details to User
    $user = $this->User->save($this->data) ;
                     if (!empty($user)) {
                          $this->data[' Profile ']['user_id'] = $this->User->id; // to get current save record id
                         $this->data[' Profile ']['postalcode'] = $this->data['User']['postalcode'] ; // assigning form details to Profile 
                         //$this->User->Merchantmaster->save($this->data);
                         if($this->User->Merchantmaster->save($this->data)){
                    $this->Session->setFlash(__('You have successfully registered an account. An email has been sent with further instructions.', true), 'default', array('class' => 'success'));
    $this->redirect(array('action' => 'login'));
                                
    } else {
    $this->Session->setFlash(__('The User could not be saved. Please, try again.', true), 'default', array('class' => 'error'));
    }
                 
                }
                 }
                 }
                 }


    Link to follow!

        

  2. 0 comments:

    Post a Comment