2015-11-03 72 views
-2

如何在另一個表中插入名字在這裏我的代碼在客戶表中插入數據,但我想在另一個表中插入firstname。 我的代碼註冊成功。如何在數據庫的另一個表中插入firstname?

public function actionRegister() { 

    $model = new Customer('signup'); 
    if (Yii::app()->request->getPost('Customer')) { 
     $custoerary = Yii::app()->request->getPost('Customer'); 
     $model->attributes = $custoerary; 
     $model->_active = 1; 
     $model->last_visted = date('Y-m-d H:i:s'); 
     $model->date_added = date('Y-m-d H:i:s'); 
     $model->store_id = $this->store_id; 

     if ($model->validate()) { 
      $model->password = md5($custoerary['password']); 
      $model->confirmpassword = md5($custoerary['confirmpassword']); 
      if ($model->save()) { 
       $selectmode = Customer::model()->find("store_id='" . $this->store_id . "' and email='" . $model->email . "' and password='" . md5($custoerary['password']) . "' "); 
       if (count($selectmode) != 0) { 
        Yii::app()->session['customer'] = $selectmode->id; 
        if (isset($_GET['redirect'])) { 
         $this->redirect(urldecode($_GET['redirect'])); 
        } 
        $this->redirect('./'); 
       } else { 
        $error = "Connection Error! Try again Later"; 
       } 
      } else { 
       $error = CHtml::errorSummary($model); 
      } 
     } else { 
      $error = "Emailid already Exists!"; 
     } 
    } 
    if ($this->session_id != 0) { 
     if (isset($_GET['redirect'])) { 
      $this->redirect(urldecode($_GET['redirect'])); 
     } 
     $this->redirect('./'); 
    } 



    $this->render('signup', array('error' => $error, 'facebookurl' => $loginUrlFacebook, 'googleurl' => $loginUrlGoogle, 'model' => $model, 'model_advertisement' => $model_advertisement, 'model_slider' => $model_slider, 'model_product' => $model_product, 'model_category' => $model_category, 'model_brand' => $model_brand), false, true); 
} 

我想當客戶註冊成功,當時名字將插入另一個表中。如何?

回答

0

您需要相關類的模型的值要插入

$myModel = new YourClassName ; 

然後分配給該模型中的價值你喜歡

$myModel->usename = $yourvalue 

然後保存

$myModel->save(); 

你可以在保存註冊值後添加此代碼

 if ($model->validate()) { 
     $model->password = md5($custoerary['password']); 
     $model->confirmpassword = md5($custoerary['confirmpassword']); 
     if ($model->save()) { 
      // here 
      $myModel = new YourClassName ; 
      $myModel->usename = $yourvalue 
      $myModel->save(); 
      ....... 
+0

好的,但我在哪裏寫這段代碼? –

+0

我已更新答案 – scaisEdge

+0

註冊成功,但沒有存儲數據 –

1
if ($model->validate()) { 
      $model->password = md5($custoerary['password']); 
      $model->confirmpassword = md5($custoerary['confirmpassword']); 
      if ($model->save()) { 
       $name= "kevin"; 
       $myModel = new CustomerLifecycle('signup') ; 
       $myModel->message = $name; 
       $myModel->save(); 
相關問題