/** * 文章添加 */ public function actionCreate() { $model = new Article(); $addonarticle = new Addonarticle(); if (isset($_POST['Article'])) { $transaction = Yii::app()->db->beginTransaction(); try { $model->attributes = $_POST['Article']; if (!$model->save()) { Tool::logger('article', var_export($model->getErrors(), true)); throw new CException('文章生成失败'); } $aid = $model->primaryKey; $addonarticle->attributes = $_POST['Addonarticle']; if (!$addonarticle->save()) { Tool::logger('article', var_export($addonarticle->getErrors(), true)); throw new CException('文章附表生成失败'); } $this->redirect(array('list')); } catch (Exception $e) { Tool::logger('article', $e->getMessage()); $transaction->rollback(); } } $this->render('create', array('model' => $model, 'addonarticle' => $addonarticle)); }