当前位置: 首页>>代码示例>>PHP>>正文


PHP DataMapper::save方法代码示例

本文整理汇总了PHP中DataMapper::save方法的典型用法代码示例。如果您正苦于以下问题:PHP DataMapper::save方法的具体用法?PHP DataMapper::save怎么用?PHP DataMapper::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataMapper的用法示例。


在下文中一共展示了DataMapper::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save

 function save($o = null, $log = true)
 {
     $action = $this->id ? 'updated' : 'inserted';
     parent::save($o);
     if ($log) {
         $this->logActivity($action);
     }
 }
开发者ID:broofa,项目名称:socipedia,代码行数:8,代码来源:basemodel.php

示例2: testShouldListPossibleParents

 function testShouldListPossibleParents()
 {
     $mapper = new DataMapper($this->db);
     $parent1_id = $mapper->save(array('name' => 'Parent 1'));
     $mapper = new DataMapper($this->db);
     $parent2_id = $mapper->save(array('name' => 'Parent 1a', 'paths' => array($parent1_id)));
     $form = new Form($mapper);
     $expected = array($parent1_id => 'Parent 1', $parent1_id . '/' . $parent2_id => 'Parent 1a');
     $this->assertEquals($expected, $form->getElement('paths')->getMultiOptions());
 }
开发者ID:metator,项目名称:application,代码行数:10,代码来源:FormTest.php

示例3: testShouldUpdateAddress

 function testShouldUpdateAddress()
 {
     $address = array('first_name' => 'Joshua', 'last_name' => 'Ribakoff', 'email' => 'josh.ribakoff@gmail.com', 'address' => '123 Test St', 'address2' => 'Suite 5', 'city' => 'Port St Lucie', 'state' => 'FL', 'postal' => '00123', 'country' => 'USA', 'phone' => '0101010101', 'fax' => '0202020202');
     $addressMapper = new DataMapper($this->db);
     $id = $addressMapper->save($address);
     $updatedAddress = array('id' => $id, 'first_name' => 'Joshua-updated', 'last_name' => 'Ribakoff-updated', 'email' => 'josh.ribakoff-updated@gmail.com', 'address' => '123 Test St-updated', 'address2' => 'Suite 5-updated', 'city' => 'Port St Lucie-updated', 'state' => 'FL-updated', 'postal' => '12345', 'country' => 'USA-updated', 'phone' => '111111111', 'fax' => '2222222222');
     $addressMapper = new DataMapper($this->db);
     $id = $addressMapper->save($updatedAddress);
     $loadedAddress = $addressMapper->load($id);
     $this->assertSame($updatedAddress, $loadedAddress, 'should save new address');
 }
开发者ID:metator,项目名称:application,代码行数:11,代码来源:DataMapperTest.php

示例4: save

 public function save($object = '', $related_field = '')
 {
     if ($this->_before_save() === false) {
         return false;
     }
     $result = parent::save($object, $related_field);
     if ($result) {
         $this->_after_save();
     }
     return $result;
 }
开发者ID:andrewkrug,项目名称:repucaution,代码行数:11,代码来源:ikantamdatamapper.php

示例5: testShouldSaveCartAndItems

 function testShouldSaveCartAndItems()
 {
     $cart = new \Metator\Cart\Cart();
     $cart->add(1, 9.99);
     $cart->add(2, 4.99);
     $cart->setQuantity(2, 2);
     $order = array('items' => $cart, 'created' => '0000-00-00 00:00:00');
     $orderMapper = new DataMapper($this->db);
     $id = $orderMapper->save($order, null);
     $reloaded_order = $orderMapper->load($id);
     $this->assertEquals(array(1, 2), $reloaded_order['items']->items(), 'should save items');
 }
开发者ID:metator,项目名称:application,代码行数:12,代码来源:DataMapperTest.php

示例6: save

 function save($object = '')
 {
     if (empty($this->id) and empty($object)) {
         $s = new Section();
         $s->where('sort >=', $this->sort);
         //$s->where( 'parent_section', $this->parent_section );
         $s->get();
         foreach ($s->all as $item) {
             $item->sort++;
             $item->save();
         }
     }
     parent::save($object);
 }
开发者ID:sigit,项目名称:vunsy,代码行数:14,代码来源:section.php

示例7: save

 /**
  * save current section 
  * and prevent collision if it is a new object
  */
 public function save($object = '', $related_field = '')
 {
     if (empty($this->id) and empty($object)) {
         $s = new Section();
         $s->where('sort >=', $this->sort);
         $s->where('parent_section', $this->parent_section);
         $s->get();
         foreach ($s as $item) {
             $item->sort++;
             $item->save();
         }
     }
     parent::save($object, $related_field);
 }
开发者ID:kabircse,项目名称:Codeigniter-Egypt,代码行数:18,代码来源:section.php

示例8: save

 function save($object = '', $related_field = '')
 {
     if (!$this->exists() || empty($this->code)) {
         $o = new CurriculumViate();
         $o->select_max('position');
         $o->get();
         if (count($o->all) != 0) {
             $max = $o->position + 1;
             $this->position = $max;
         } else {
             $this->postion = 1;
         }
     }
     return parent::save($object, $related_field);
 }
开发者ID:lxthien,项目名称:batdongsan,代码行数:15,代码来源:curriculumVitae.php

示例9: save

 function save($object = '', $related_field = '')
 {
     if (!$this->exists()) {
         $o = new Estatetype();
         $o->select_max('position');
         $o->get();
         if (count($o->all) != 0) {
             $max = $o->position + 1;
             $this->position = $max;
         } else {
             $this->postion = 1;
         }
     }
     return parent::save($object, $related_field);
 }
开发者ID:lxthien,项目名称:batdongsan,代码行数:15,代码来源:estatetype.php

示例10: save

 function save($object = '', $related_field = '')
 {
     if (!$this->exists()) {
         $o = new productcatspec();
         $o->where("productcat_id", $this->productcat_id);
         $o->select_max('position');
         $o->get();
         if (count($o->all) != 0) {
             $max = $o->position + 1;
             $this->position = $max;
         } else {
             $this->postion = 1;
         }
     }
     return parent::save($object, $related_field);
 }
开发者ID:lxthien,项目名称:batdongsan,代码行数:16,代码来源:productcatspec.php

示例11: save

 public function save($task = null, $user = null)
 {
     if ($user == null) {
         $user = $this->user;
     }
     if ($task == null) {
         $task = $this->task;
     }
     if ($user == null) {
         throw new UserNotFound();
     }
     if ($task == null) {
         throw new Task_Not_Found();
     }
     $this->checkOverlap($task);
     return parent::save(array($user, $task));
 }
开发者ID:rezachess,项目名称:Planning,代码行数:17,代码来源:goal.php

示例12: save

 function save($object = '', $related_field = '')
 {
     if (!$this->exists() || empty($this->code)) {
         $o = new Cartitem();
         $o->select_max('position');
         $o->get();
         if (count($o->all) != 0) {
             $max = $o->position + 1;
             $this->position = $max;
         } else {
             $this->postion = 1;
         }
         $position = (string) $this->position;
         $l = 6 - strlen($position);
         $st = "";
         for ($i = 0; $i < $l; $i++) {
             $st .= "0";
         }
         $position = $st . $position;
         $this->code = $position;
     }
     return parent::save($object, $related_field);
 }
开发者ID:lxthien,项目名称:batdongsan,代码行数:23,代码来源:cartitem.php

示例13: save

 /**
  * @param string $object
  * @param string $related_field
  * @return bool
  */
 public function save($object = '', $related_field = '')
 {
     $this->last_check = time();
     $result = parent::save($object, $related_field);
     return $result;
 }
开发者ID:andrewkrug,项目名称:repucaution,代码行数:11,代码来源:instagram_follower.php

示例14: save

 public function save($object = '', $related_field = '')
 {
     $is_new = FALSE;
     if ($this->_force_save_as_new or !$this->id) {
         $is_new = TRUE;
     }
     $this->trigger_event('before_save');
     /* keep copy of the stored because it resets to new after save */
     $this->_keep_old();
     $return = parent::save($object, $related_field);
     /* if new then get it to load relations */
     if ($return && $is_new && ($this->has_one or $this->has_many)) {
         $this->where('id', $this->id)->get();
     }
     if ($return) {
         $this->trigger_event('after_save');
     }
     return $return;
 }
开发者ID:RCMmedia,项目名称:rubicon,代码行数:19,代码来源:MY_Model.php

示例15: array

 /**
  * Convert an associative array back into a DataMapper model.
  *
  * If $fields is provided, missing fields are assumed to be empty checkboxes.
  * Alse if $sub_array is TRUE, will save related object provided by sub array
  *
  * @param    DataMapper $object The DataMapper Object to save to.
  * @param    array $data A an associative array of fields to convert.
  * @param    array $fields Array of 'safe' fields.  If empty, only includes the database columns.
  * @param    bool $sub_array If TRUE - will save provided by subarray related obj
  * @param    bool $save If TRUE, then attempt to save the object automatically.
  * @return    array|bool A list of newly related objects, or the result of the save if $save is TRUE.
  * If $sub_array TRUE, return array('error','created_ids')
  */
 function save_from($object, $data, $fields = '', $sub_array = FALSE, $save = TRUE)
 {
     // keep track of newly related objects
     $new_related_objects = array();
     $error = '';
     //error string
     $created_ids = array();
     //stores array of newly created ids ('related_class_name' => array(ids))
     // Assume all database columns.
     // In this case, simply store $fields that are in the $data array.
     $object_fields = $object->fields;
     if (in_array('password', $object_fields)) {
         $object_fields[] = 'password_confirm';
     }
     foreach ($data as $k => $v) {
         if (in_array($k, $object_fields)) {
             $object->{$k} = $v;
         }
     }
     if (!empty($fields)) {
         // If $fields is provided, assume all $fields should exist.
         foreach ($fields as $f) {
             if (array_key_exists($f, $object->has_one)) {
                 // Store $has_one relationships
                 $c = get_class($object->{$f});
                 $rel = new $c();
                 $id = isset($data[$f]) ? $data[$f] : 0;
                 $rel->get_by_id($id);
                 if ($rel->exists()) {
                     // The new relationship exists, save it.
                     $new_related_objects[$f] = $rel;
                 } else {
                     // The new relationship does not exist, delete the old one.
                     $object->delete($object->{$f}->get());
                 }
             } else {
                 if (array_key_exists($f, $object->has_many)) {
                     // Store $has_many relationships
                     $c = get_class($object->{$f});
                     $ids = isset($data[$f]) ? $data[$f] : FALSE;
                     $has_join_table = false;
                     if (!empty($object->has_many[$f]['join_table'])) {
                         $has_join_table = true;
                         //so, do not delete the record, only the relation
                     }
                     if ($sub_array) {
                         $error_classes_to_check = array();
                         $created_ids[$f] = array();
                         if (empty($ids)) {
                             $old_related_obj = $object->{$f}->select('id')->get();
                             if ($has_join_table) {
                                 $object->delete($old_related_obj);
                                 //delete relation to related object
                             } else {
                                 $old_related_obj->delete_all();
                                 //delete related object
                             }
                         } else {
                             $related_ids = array();
                             foreach ($ids as $related_row) {
                                 $create = false;
                                 if (isset($related_row['id']) && $related_row['id']) {
                                     $id = $related_row['id'];
                                     $related_ids[] = $id;
                                     //add to list of provided ids
                                     unset($related_row['id']);
                                     //useless any more
                                 } else {
                                     $id = null;
                                     $create = true;
                                 }
                                 $related_obj = new $c($id);
                                 foreach ($related_row as $column => $value) {
                                     $related_obj->{$column} = $value;
                                     //fill object with new values
                                 }
                                 if ($create) {
                                     //create new record
                                     if (!$related_obj->save()) {
                                         $error .= $related_obj->error->string;
                                     } else {
                                         $created_ids[$f][] = $related_obj->id;
                                         //add id to returned array
                                     }
                                 }
                                 $error_classes_to_check[] = $f;
//.........这里部分代码省略.........
开发者ID:andrewkrug,项目名称:repucaution,代码行数:101,代码来源:save_from.php


注:本文中的DataMapper::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。