本文整理汇总了PHP中Worker::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Worker::save方法的具体用法?PHP Worker::save怎么用?PHP Worker::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Worker
的用法示例。
在下文中一共展示了Worker::save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionAddWorker
function actionAddWorker()
{
$model = new Worker();
$user = new User();
$u_transaction = $user->dbConnection->beginTransaction();
$this->performAjaxValidation($user);
if (isset($_POST['Worker'])) {
if (isset($_POST['User'])) {
$user->login = $_POST['User']['login'];
$user->password = $_POST['User']['password'];
$user->role = 'worker';
if ($user->save()) {
$model->attributes = $_POST['Worker'];
$model->user_id = $user->id;
$timestamp = CDateTimeParser::parse($model->birthdate, 'dd-MM-yyyy');
$model->birthdate = date('Y-m-d', $timestamp);
if ($model->save()) {
$u_transaction->commit();
$this->redirect(array('view', 'id' => $model->user_id));
} else {
$u_transaction->rollback();
//откатываем данные по юзеру, в случае если данные по работнику не сохранились
throw new CHttpException(901, 'Ошибка сохранения данных работника.');
}
} else {
throw new CHttpException(902, "Ошибка сохранения данных авторизации");
}
} else {
throw new CHttpException(903, 'Ошибка передачи данных авторизации.');
}
} else {
$this->render('add_worker', array('model' => $model, 'user' => $user));
}
}
示例2: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Worker();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Worker'])) {
$model->attributes = $_POST['Worker'];
if ($model->save()) {
$this->redirect(array('admin'));
}
}
$this->render('create', array('model' => $model));
}