Skip to content

Instantly share code, notes, and snippets.

@dedikisme
Created December 30, 2014 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dedikisme/b47868b75dbac8fe5703 to your computer and use it in GitHub Desktop.
Save dedikisme/b47868b75dbac8fe5703 to your computer and use it in GitHub Desktop.
<?php
//class Controller
public function actionContact()
{
$model = new DynamicModel([
'name', 'body'
]);
$model->addRule(['name', 'body'], 'required')
->addRule(['name'],'unique');
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
echo json_encode($model->attributes);
exit();
return $this->refresh();
}
return $this->render('contact', ['model' => $model]);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment