Gc\Media\Icon\Model::save PHP Méthode

save() public méthode

Save icon
public save ( ) : integer
Résultat integer
    public function save()
    {
        $this->events()->trigger(__CLASS__, 'before.save', $this);
        $arraySave = array('name' => $this->getName(), 'url' => $this->getUrl());
        try {
            if ($this->getId() == null) {
                $this->insert($arraySave);
                $this->setId($this->getLastInsertId());
            } else {
                $this->update($arraySave, array('id' => (int) $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

Exemple #1
0
 /**
  * Test
  *
  * @return void
  */
 public function testDelete()
 {
     $this->object->setData(array('name' => 'IconTest', 'url' => 'IconTest'));
     $this->object->save();
     $this->assertTrue($this->object->delete());
 }