如何在数据库中的另一个表中插入firstname?

时间:2015-11-03 09:50:32

标签: php mysql yii

如何在另一个表中插入firstname我的代码在customer表中插入数据,但我想在另一个表中插入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);
}

我想当客户在那时成功注册时,firstname将插入另一个表中。怎么样?

2 个答案:

答案 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();

答案 1 :(得分: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();
            .......