本文整理汇总了PHP中Course::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Course::save方法的具体用法?PHP Course::save怎么用?PHP Course::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Course
的用法示例。
在下文中一共展示了Course::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
public static function store()
{
$params = $_POST;
$course_params = array('name' => $params['name'], 'city' => $params['city']);
$course = new Course($course_params);
$errors = $course->errors();
$number_of_holes = count($params) - count($course_params) - 1;
// one hidden input for hole_count
// Check hole validity before saving anything
$holes = array();
for ($hole_num = 1; $hole_num <= $number_of_holes; $hole_num++) {
$par = $params['hole' . $hole_num];
$hole = new Hole(array('hole_num' => $hole_num, 'par' => $par));
$holes[] = $hole;
$errors = array_merge($errors, $hole->errors());
}
if (count($errors) == 0) {
// Course and holes were all valid
$courseid = $course->save();
$course->number_of_holes = count($holes);
foreach ($holes as $hole) {
$hole->courseid = $courseid;
$hole->save();
}
Redirect::to('/course/' . $courseid, array('message' => 'Rata ja sen väylät lisätty.'));
} else {
View::make('course/new.html', array('errors' => $errors, 'attributes' => $params, 'hole_count' => $params['hole_count']));
}
}
示例2: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param PropelPDO $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(PropelPDO $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aCourse !== null) {
if ($this->aCourse->isModified() || $this->aCourse->isNew()) {
$affectedRows += $this->aCourse->save($con);
}
$this->setCourse($this->aCourse);
}
if ($this->isNew() || $this->isModified()) {
// persist changes
if ($this->isNew()) {
$this->doInsert($con);
} else {
$this->doUpdate($con);
}
$affectedRows += 1;
$this->resetModified();
}
$this->alreadyInSave = false;
}
return $affectedRows;
}
示例3: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param PropelPDO $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(PropelPDO $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aInstructor !== null) {
if ($this->aInstructor->isModified() || $this->aInstructor->isNew()) {
$affectedRows += $this->aInstructor->save($con);
}
$this->setInstructor($this->aInstructor);
}
if ($this->aCourse !== null) {
if ($this->aCourse->isModified() || $this->aCourse->isNew()) {
$affectedRows += $this->aCourse->save($con);
}
$this->setCourse($this->aCourse);
}
if ($this->isNew()) {
$this->modifiedColumns[] = CourseInstructorAssociationPeer::ID;
}
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$pk = CourseInstructorAssociationPeer::doInsert($this, $con);
$affectedRows += 1;
// we are assuming that there is only 1 row per doInsert() which
// should always be true here (even though technically
// BasePeer::doInsert() can insert multiple rows).
$this->setId($pk);
//[IMV] update autoincrement primary key
$this->setNew(false);
} else {
$affectedRows += CourseInstructorAssociationPeer::doUpdate($this, $con);
}
$this->resetModified();
// [HL] After being saved an object is no longer 'modified'
}
if ($this->collCourseRatings !== null) {
foreach ($this->collCourseRatings as $referrerFK) {
if (!$referrerFK->isDeleted()) {
$affectedRows += $referrerFK->save($con);
}
}
}
if ($this->collAutoCourseRatings !== null) {
foreach ($this->collAutoCourseRatings as $referrerFK) {
if (!$referrerFK->isDeleted()) {
$affectedRows += $referrerFK->save($con);
}
}
}
$this->alreadyInSave = false;
}
return $affectedRows;
}
示例4: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Course();
$batch = new Batch();
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation(array($model, $batch));
if (isset($_POST['Course'])) {
$model->attributes = $_POST['Course'];
$model->created_by = Yii::app()->user->id;
$model->created_date = new CDbExpression('NOW()');
if ($model->save()) {
if (isset($_POST['Batch'])) {
$batch->batch_name = $_POST['Batch']['batch_name'];
$batch->batch_fees = $_POST['Batch']['batch_fees'];
$batch->course_id = $model->course_id;
$batch->batch_start_date = '';
$batch->batch_end_date = '';
$batch->batch_created_by = Yii::app()->user->id;
$batch->batch_creation_date = new CDbExpression('NOW()');
$batch->save(false);
}
$this->redirect(array('view', 'id' => $model->course_id));
}
}
$this->render('create', array('model' => $model, 'batch' => $batch));
}
示例5: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Course();
$model->scenario = 'create';
if (isset($_POST['Course'])) {
$model->attributes = $_POST['Course'];
if ($model->save()) {
$this->redirect(array('index'));
}
}
$this->render('create', array('model' => $model));
}
示例6: Course
function test_save()
{
//Arrange
$course_name = "Monster Literature";
$course_number = "ENG304";
$test_course = new Course($course_name, $course_number);
$test_course->save();
//Act
$result = Course::getAll();
//Assert
$this->assertEquals($test_course, $result[0]);
}
示例7: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Course();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Course'])) {
$model->attributes = $_POST['Course'];
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例8: testSave
function testSave()
{
//Arrange
$course_name = "HISTORY";
$number = 101;
$test_course = new Course($course_name, $number);
//var_dump($test_course);
//Act
$test_course->save();
//Assert
$result = Course::getAll();
$this->assertEquals($test_course, $result[0]);
}
示例9: Course
function testCreate_OneToMany()
{
$this->_createModelAndIncludeThem('lecture', 'Lecture');
$this->_createModelAndIncludeThem('course', 'Course');
$course = new Course();
$course->setTitle($course_title = 'bar');
$course->save();
$lecture = new Lecture();
$lecture->setTitle($lecture_title = 'foo');
$lecture->setCourse($course);
$lecture->save();
$loaded_lecture = lmbActiveRecord::findById('Lecture', $lecture->getId());
$this->assertEqual($loaded_lecture->getTitle(), $lecture_title);
$this->assertEqual($loaded_lecture->getCourse()->getId(), $course->getId());
$loaded_course = lmbActiveRecord::findById('Course', $course->getId());
$this->assertEqual($loaded_course->getLectures()->at(0)->getId(), $lecture->getId());
}
示例10: Course
function test_addStudent_and_getStudents()
{
$name = "Western Civ";
$number = "HST 101";
$test_course = new Course($name, $number);
$test_course->save();
$name = "Chris";
$date = "1111-11-11";
$test_student = new Student($name, $date);
$test_student->save();
$name2 = "Dillon";
$test_student2 = new Student($name2, $date);
$test_student2->save();
$test_course->addStudent($test_student);
$test_course->addStudent($test_student2);
$this->assertEquals($test_course->getStudents(), [$test_student, $test_student2]);
}
示例11: Course
function test_addCourse_and_getCourses()
{
$name = "Western Civ";
$number = "HST 101";
$test_course = new Course($name, $number);
$test_course->save();
$name2 = "Remedial Math";
$number2 = "MTH 64";
$test_course2 = new Course($name2, $number2);
$test_course2->save();
$name = "Chris";
$date = "1111-11-11";
$test_student = new Student($name, $date);
$test_student->save();
$test_student->addCourse($test_course);
$test_student->addCourse($test_course2);
$this->assertEquals($test_student->getCourses(), [$test_course, $test_course2]);
}
示例12: save
public function save()
{
$adminId = Session::get('admin_id');
if (!isset($adminId)) {
return json_encode(array('message' => 'not logged'));
}
$instituteId = Session::get('institute_id');
if (!isset($instituteId)) {
return json_encode(array('message' => 'invalid'));
}
$course = new Course();
$course->institute_id = $instituteId;
$course->name = Input::get('name');
$course->description = Input::get('description');
$course->status = 'active';
$course->created_at = date('Y-m-d h:i:s');
$course->save();
return json_encode(array('message' => 'done'));
}
示例13: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new Course;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Course']))
{
$_POST['Course']['course_img']=$_FILES['Course']['name']['course_img'];
$model->attributes=$_POST['Course'];
$model->logo=$_FILES['Course'];
if($model->save())
$this->redirect(array('view','id'=>$model->course_ID));
}
$this->render('create',array(
'model'=>$model,
));
}
示例14: store
/**
* Attempts to save new course and redirect to the newly created course.
*/
public static function store()
{
$player = self::get_user_logged_in();
if (!$player) {
View::make('player/login.html', array('error' => 'Vain kirjautuneet käyttäjät voivat lisätä ratoja.'));
}
$params = $_POST;
$params['url'] = self::fix_url($params['url']);
$params['mapLink'] = self::fix_url($params['mapLink']);
$attributes = array('name' => $params['name'], 'description' => $params['description'], 'address' => $params['address'], 'mapLink' => $params['mapLink'], 'url' => $params['url']);
$course = new Course($attributes);
$errors = $course->errors();
if (count($errors) == 0) {
$course->save();
Hole::create_holes($params['holes'], $course->id);
Moderator::add_as_moderator($course->id, $player->id);
Redirect::to('/course/' . $course->id . '/edit', array('message' => 'Rata lisätty, täydennä vielä väylien tiedot.'));
} else {
View::make('course/new.html', array('errors' => $errors, 'attributes' => $attributes));
}
}
示例15: actionCreate
public function actionCreate()
{
if (!Yii::app()->user->getId()) {
Yii::app()->user->loginRequired();
}
$model = new Course();
if ($_POST['Course']) {
$time_area = '';
if ($_POST['Course']['time_area']) {
$time_area = serialize($_POST['Course']['time_area']);
}
$_POST['Course']['time_area'] = $time_area;
$model->attributes = $_POST['Course'];
if ($model->validate() && $model->save()) {
Yii::app()->user->setFlash('course', '创建成功');
$this->redirect(array('course/index'));
}
}
$stores = Store::model()->getName();
$this->render('create', ['model' => $model, 'stores' => $stores]);
}