Newscoop\Service\Template::deleteItem PHP Метод

deleteItem() публичный Метод

Delete item
public deleteItem ( string $key ) : void
$key string
Результат void
    public function deleteItem($key)
    {
        if ($this->repository->isUsed($key) || $this->storage->isUsed($key)) {
            throw new \InvalidArgumentException(sprintf("The template object %s is in use and can not be deleted.", $key));
        }
        try {
            $this->storage->deleteItem($key);
            $this->repository->delete($key);
        } catch (\InvalidArgumentException $e) {
            throw new \InvalidArgumentException(sprintf("Can't remove non empty directory '%s'", basename($key)), $e->getCode(), $e);
        }
    }

Usage Example

Пример #1
0
 /**
  * @Acl(action="delete")
  */
 public function deleteAction()
 {
     $path = $this->parsePath();
     $files = $this->_getParam('file', array());
     try {
         foreach ((array) $files as $file) {
             $key = "{$path}/{$file}";
             $this->service->deleteItem($key);
             $this->_helper->entity->flushManager();
             $this->clearCompiledTemplate($key);
             $this->_helper->flashMessenger(getGS("Template object '\$1' was deleted.", $file));
         }
     } catch (\InvalidArgumentException $e) {
         $this->_helper->flashMessenger(array('error', $e->getMessage()));
     }
     $this->_redirect(urldecode($this->_getParam('next')), array('prependBase' => false));
 }
All Usage Examples Of Newscoop\Service\Template::deleteItem