Gc\Datatype\Model::save PHP Method

save() public method

Save Datatype model
public save ( ) : integer
return integer
    public function save()
    {
        $this->events()->trigger(__CLASS__, 'before.save', $this);
        $arraySave = array('name' => $this->getName(), 'prevalue_value' => serialize($this->getPrevalueValue()), 'model' => $this->getModel());
        try {
            $id = $this->getId();
            if (empty($id)) {
                $this->insert($arraySave);
                $this->setId($this->getLastInsertId());
            } else {
                $this->update($arraySave, array('id' => $this->getId()));
            }
            $this->events()->trigger(__CLASS__, 'after.save', $this);
            return $this->getId();
        } catch (\Exception $e) {
            $this->events()->trigger(__CLASS__, 'after.save.failed', $this);
            throw new \Gc\Exception($e->getMessage(), $e->getCode(), $e);
        }
    }

Usage Example

コード例 #1
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 protected function setUp()
 {
     $this->datatype = DatatypeModel::fromArray(array('name' => 'AbstractDatatype', 'prevalue_value' => 's:16:"AbstractDatatype";', 'model' => 'AbstractDatatype'));
     $this->datatype->save();
     $this->object = $this->getMockForAbstractClass('Gc\\Datatype\\AbstractDatatype');
     $application = Registry::get('Application');
     $this->object->setRequest($application->getServiceManager()->get('Request'));
     $this->object->setRouter($application->getServiceManager()->get('Router'));
     $this->object->setHelperManager($application->getServiceManager()->get('viewhelpermanager'));
     $this->object->load($this->datatype, 1);
 }
All Usage Examples Of Gc\Datatype\Model::save