コード例 #1
0
 protected function validationRules(AbstractEntity $entity)
 {
     foreach ($entity->getData() as $key => $value) {
         // Check if post is not longer than 20 characters
         if ($key == 'post' && strlen($value) > 140) {
             $this->addValidationError($key, "Should not exceed 20 characters");
         }
     }
 }
コード例 #2
0
 /**
  * Persist data to the Database
  *
  * @param  Entity $entity   Entity to be saved
  *
  * @return int              A number of affected rows
  */
 public function save(AbstractEntity $entity)
 {
     // Execute an update if ID is present in data
     if ($entity->getData($this->entityIdColumnName) != null) {
         // If ID is present, run an update statement and check if one record is updated
         return $this->adapter->update($entity->getData());
     }
     // Otherwise, run an insert statement and check if one record is added
     return $this->adapter->insert($entity->getData());
 }