create() public method

Create a new resource
public create ( mixed $data ) : mixed
$data mixed
return mixed
Beispiel #1
0
 public function create($data)
 {
     if (!$this->getOptions()->getRestEnabled()) {
         return parent::create($data);
     }
     $request = $this->getRequest();
     $formData = array_merge_recursive($data, $request->getFiles()->toArray());
     $routeMatch = $this->getEvent()->getRouteMatch();
     $id = $this->getIdentifier($routeMatch, $request);
     if (!empty($id)) {
         return $this->update($id, $formData);
     }
     $this->getResponse()->getHeaders()->addHeaderLine('Content-Type', 'application/json');
     $item = $this->getItem();
     $form = $this->getCreateForm();
     $result = array('success' => false);
     if ($this->_createItem($item, $form, $formData)) {
         $result['success'] = true;
         $result['item'] = $this->itemToSerializable($item);
     }
     return new JsonModel($result);
 }
Beispiel #2
0
 /**
  * @param array|\Traversable $data
  * @return mixed|\Zend\Stdlib\ResponseInterface
  */
 public function create($data)
 {
     parent::create($data);
 }