Xpressengine\Draft\DraftRepository::insert PHP Method

insert() public method

새로운 임시저장 데이터 레코드를 삽입
public insert ( DraftEntity $draft ) : DraftEntity
$draft DraftEntity 임시저장 객체
return DraftEntity
    public function insert(DraftEntity $draft)
    {
        $attributes = array_merge($draft->getAttributes(), ['id' => $this->keygen->generate(), 'createdAt' => date('Y-m-d H:i:s')]);
        $this->conn->table($this->table)->insert($attributes);
        return $this->createItem($attributes);
    }

Usage Example

 /**
  * 임시 데이터 저장
  *
  * @param string $key    구분할 수 있는 키(중복가능)
  * @param mixed  $val    저장될 내용
  * @param array  $etc    기타 값들
  * @param bool   $isAuto 자동 저장 인지 여부
  * @return DraftEntity
  */
 public function set($key, $val, array $etc = [], $isAuto = false)
 {
     if ($this->auth->guest()) {
         return null;
     }
     $draft = new DraftEntity();
     $draft->fill(['userId' => $this->auth->user()->getId(), 'key' => $key, 'val' => $val, 'etc' => serialize($etc), 'isAuto' => $isAuto ? 1 : 0]);
     return $this->repo->insert($draft);
 }
All Usage Examples Of Xpressengine\Draft\DraftRepository::insert