public function actionAdd() { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; if ($params = Yii::$app->getRequest()->getBodyParams()) { $pessoa = new Pessoa(); $pessoa->load($params); if ($pessoa->save()) { //Depois que efetuei um insert apenas faço esse link para salvar. $pessoa->link('idAudiencias', Audiencia::findOne($params['Audiencia']['id'])); return $pessoa->getLi(); } } }
/** * Finds the Audiencia model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Audiencia the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Audiencia::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }