本文整理汇总了PHP中Subjects::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Subjects::save方法的具体用法?PHP Subjects::save怎么用?PHP Subjects::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subjects
的用法示例。
在下文中一共展示了Subjects::save方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Subjects();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Subjects'])) {
$model->attributes = $_POST['Subjects'];
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->idSubjects));
}
}
$this->render('create', array('model' => $model));
}
示例2: actionCreate
public function actionCreate()
{
$model = new Subjects('insert');
$users_list = CHtml::listData(Users::model()->findAll(), 'id', 'username');
if (Yii::app()->request->isPostRequest) {
$classroom = Yii::app()->request->getParam('Subjects');
$model->setAttributes($classroom);
if (!Yii::app()->user->checkAccess('admin')) {
$model->setAttribute('owner_id', Yii::app()->user->id);
}
if ($model->save()) {
Yii::app()->user->setFlash('success', 'Предмет успешно создан');
$this->redirect(['index']);
}
}
$this->render('form', ['model' => $model, 'users_list' => $users_list]);
}
示例3: actionAdd
public function actionAdd()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$request = \Yii::$app->request;
$data = $request->post();
if ($data['name'] == '') {
return ['status' => 0, 'message' => 'Không được để trống tên'];
}
$data['created_at'] = time();
$data['updated_at'] = time();
try {
$model = new Subjects();
$model->attributes = $data;
if ($model->save()) {
return ['status' => 1, 'message' => 'Thành công'];
}
return ['status' => 0, 'message' => 'Có lỗi xảy ra'];
} catch (Exception $ex) {
return ['status' => 0, 'message' => 'Có lỗi xảy ra'];
}
}
示例4: actionAddnew1
public function actionAddnew1()
{
$model = new Subjects();
// Ajax Validation enabled
//$this->performAjaxValidation($model);
// Flag to know if we will render the form or try to add
// new jon.
$flag = true;
if (isset($_POST['Submit'])) {
$flag = false;
$model->attributes = $_POST['Subjects'];
$model->save();
}
if ($flag) {
Yii::app()->clientScript->scriptMap['jquery.js'] = false;
$this->renderPartial('create1', array('model' => $model, 'id' => 2, 'batch_id' => $_GET['val1']), false, true);
}
}
示例5: actionAjax_Create
public function actionAjax_Create()
{
if (isset($_POST['Subjects'])) {
$model = new Subjects();
//set the submitted values
$model->attributes = $_POST['Subjects'];
/*$data=SubjectName::model()->findByAttributes(array('id'=>$model->name));
if($data!=NULL)
{
$model->name=$data->name;
$model->code=$data->code;
}*/
//return the JSON result to provide feedback.
if ($model->save(false)) {
echo json_encode(array('success' => true, 'id' => $model->primaryKey));
exit;
} else {
echo json_encode(array('success' => false));
exit;
}
}
}
示例6: actionAjax_Create
public function actionAjax_Create()
{
if (isset($_POST['ElectiveGroups'])) {
$model = new ElectiveGroups();
$subject = new Subjects();
//set the submitted values
$model->attributes = $_POST['ElectiveGroups'];
//return the JSON result to provide feedback.
if ($model->save(false)) {
$subject->name = $model->name;
$subject->code = $model->code;
$subject->batch_id = $model->batch_id;
$subject->no_exams = 0;
$subject->max_weekly_classes = 3;
$subject->elective_group_id = $model->id;
$subject->is_deleted = 0;
$subject->created_at = date('Y-m-d h:i:s');
$subject->save();
echo json_encode(array('success' => true, 'id' => $model->primaryKey));
exit;
} else {
echo json_encode(array('success' => false));
exit;
}
}
}
示例7: postAddSubjects
public function postAddSubjects()
{
$validator = Validator::make(Input::all(), array('subject_name' => 'required|max:30|min:3', 'subject_code' => 'required|max:30|min:2'));
if ($validator->fails()) {
$response = array('status' => 'failed', 'msg' => 'Item is not updated', 'errors' => $validator, 'error_messages' => $validator->messages());
return Response::json($response);
} else {
$subject_id = Input::get('subject_id');
$subject_name = Input::get('subject_name');
$subject_code = Input::get('subject_code');
$class_id = Input::get('class_id');
$section_id = Input::get('section_id');
if ($subject_id) {
$subjects = Subjects::find($subject_id);
$subjects->subject_name = ucwords($subject_name);
$subjects->subject_code = strtoupper($subject_code);
if ($subjects->save()) {
$response = array('status' => 'success', 'msg' => 'Subjects created successfully', 'errors' => null, 'result' => array('subjects' => $subjects));
return Response::json($response);
}
} else {
$subjects = new Subjects();
$subjects->subject_name = ucwords($subject_name);
$subjects->subject_code = strtoupper($subject_code);
$subjects->class_id = $class_id;
$subjects->section_id = $section_id;
if ($subjects->save()) {
$response = array('status' => 'success', 'msg' => 'Setting created successfully', 'errors' => null, 'result' => array('subjects' => $subjects));
return Response::json($response);
}
}
}
$response = array('status' => 'failed', 'msg' => 'Item is not updated');
return Response::json($response);
}