add a resource

@return Response
490197
public function postDeleteResources(Request $req, $album_id, $resource_id) 
	{
		$this->authorize('admin',  Auth::user());
		$album = Album::find($album_id);
		$resource = Resource::find($resource_id);
		$nameFile = $resource->title;
		$resource->delete();
	
		return redirect(route('album.edit', $album_id))
		->with('success', 'Resource deleted: '. $nameFile);
	}
665532
public function resourceAction()
    {
        // Handle a request for an OAuth2.0 Access Token and send the response to the client
        if (!$this->server->verifyResourceRequest($this->getOAuth2Request())) {
            $response   = $this->server->getResponse();
            $parameters = $response->getParameters();
            $errorUri   = isset($parameters['error_uri']) ? $parameters['error_uri'] : null;
            return new ApiProblemResponse(
                new ApiProblem(
                    $response->getStatusCode(),
                    $parameters['error_description'],
                    $errorUri,
                    $parameters['error']
                )
            );
        }
        $httpResponse = $this->getResponse();
        $httpResponse->setStatusCode(200);
        $httpResponse->getHeaders()->addHeaders(array('Content-type' => 'application/json'));
        $httpResponse->setContent(
            json_encode(array('success' => true, 'message' => 'You accessed my APIs!'))
        );
        return $httpResponse;
    }
598860
public function add() {
		if ($this->request->is('post')) {
			$this->Cliente->create();
			if ($this->Cliente->save($this->request->data)) {
				$this->Session->setFlash(__('The %s has been saved.', Configure::read('Mesa.tituloCliente')));
				return $this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The %s could not be saved. Please, try again.', Configure::read('Mesa.tituloCliente')));
			}
		}
		$descuentos = $this->Cliente->Descuento->find('list');
		$tipoDocumentos = $this->Cliente->TipoDocumento->find('list');
		$ivaResponsabilidades = $this->Cliente->IvaResponsabilidad->find('list');
		$this->set(compact('descuentos', 'tipoDocumentos', 'ivaResponsabilidades'));
		$this->render('form');
	}
810494
public function createRequest()
    {
        return $this->getHttpClient()
            ->createRequest()
            ->addOptions($this->defaultRequestOptions())
            ->addOptions($this->getRequestOptions());
    }
143236
protected function add()
    {
        $nodeRef = $this->buildCmsNodeRef($slugKey = null);

        if (!$this->buttonPushed()) {

            $node = $nodeRef->generateNode();
            $node->setNodePartials(new NodePartials('all', 'fields', 'fields'));

            $this->NodeMapper->defaultsOnNode($node);

            $this->NodeBinder->bindPersistentFields($node, $this->getErrors(), $this->params, $this->rawParams);
            $this->NodeBinder->fireAddBindEvents($node, $this->getErrors(), $this->params, $this->rawParams);

            $location = 'load';
            $this->Events->trigger('NodeCmsController.add'.'.'.$location, $this->errors, $this->templateVars, $node);
            foreach ((array)$nodeRef->getElement()->getAspects() as $aspect)
                $this->Events->trigger('NodeCmsController.@'.$aspect->Slug.'.'.'add'.'.'.$location, $this->errors, $this->templateVars, $node);

            if($node->hasTitle() && !$node->hasSlug())
                $node->Slug = SlugUtils::createSlug($node->Title, $node->getNodeRef()->getElement()->AllowSlugSlashes);

            $this->bindNodeToActionDatasource($node);

            //show form view (action_form_view)
            return new View($this->formView());

            //*** at this point the only subsequent actions will result from button presses
        }

        if ($this->cancelButtonPushed() || $this->deleteConfirmButtonPushed()) {

            // $this->service->delete($id);

            $view = new View($this->cancelView());

            $location = 'cancel';
            $this->Events->trigger('NodeCmsController.add'.'.'.$location,
                                    $this->errors, $this->templateVars, $view);
            foreach ((array)$nodeRef->getElement()->getAspects() as $aspect)
                $this->Events->trigger('NodeCmsController.@'.$aspect->Slug.'.'.'add'.'.'.$location,
                                        $this->errors, $this->templateVars, $view);

            //redirect to pages list (action_cancel_view)
            return $view;
        }

        if ($this->saveButtonPushed() || $this->saveAndContinueButtonPushed() || $this->saveAndNewButtonPushed()) {

            //get default form backing object
            // $page = $this->service->getByID($id);
            try {
                $nodeRef = $this->buildCmsNodeRef($slugKey = 'Slug');

                $node = $nodeRef->generateNode();

                //bind posted params to form backing object
                $this->NodeBinder->bindPersistentFields($node, $this->getErrors(), $this->params, $this->rawParams);
                $this->NodeBinder->fireAddBindEvents($node, $this->getErrors(), $this->params, $this->rawParams);

                //FIRE EVENTS FOR PRE-ADD
                $location = 'pre';
                $this->Events->trigger('NodeCmsController.add'.'.'.$location,
                                        $this->errors, $this->templateVars, $node);
                foreach((array)$nodeRef->getElement()->getAspects() as $aspect)
                    $this->Events->trigger('NodeCmsController.@'.$aspect->Slug.'.'.'add'.'.'.$location,
                                            $this->errors, $this->templateVars, $node);

                // check permissions
                // $this->checkAddPermission($node);
                $this->checkNonce();

                $this->getErrors()->throwOnError();

                $this->RegulatedNodeService->add($node);

                $location = 'post';
                $this->Events->trigger('NodeCmsController.add'.'.'.$location,
                                            $this->errors, $this->templateVars, $node);
                foreach((array)$nodeRef->getElement()->getAspects() as $aspect)
                    $this->Events->trigger('NodeCmsController.@'.$aspect->Slug.'.'.'add'.'.'.$location,
                                            $this->errors, $this->templateVars, $node);


            } catch(ValidationException $ve) {
                $location = 'validationException';
                $this->Events->trigger('NodeCmsController.add'.'.'.$location,
                                            $this->errors, $this->templateVars, $node);
                foreach ((array)$nodeRef->getElement()->getAspects() as $aspect)
                    $this->Events->trigger('NodeCmsController.@'.$aspect->Slug.'.'.'add'.'.'.$location,
                                            $this->errors, $this->templateVars, $node);

                $this->RegulatedNodeService->resolveLinkedNodes($node, $node->getNodePartials(), true);

                //bind form backing object to datasource
                $this->bindNodeToActionDatasource($node);

                //re-throw validationexception, which shows form view
                throw $ve;
            } catch (Exception $e) {

                $this->ErrorHandler->sendErrorEmail($e);

                $this->errors->addGlobalError($e->getCode(), $e->getMessage());

                if(!empty($node))
                {
                    $location = 'validationException';
                    $this->Events->trigger('NodeCmsController.add'.'.'.$location,
                                                $this->errors, $this->templateVars, $node);

                    foreach((array)$nodeRef->getElement()->getAspects() as $aspect)
                        $this->Events->trigger('NodeCmsController.@'.$aspect->Slug.'.'.'add'.'.'.$location,
                                                $this->errors, $this->templateVars, $node);

                    $this->RegulatedNodeService->resolveLinkedNodes($node, $node->getNodePartials(), true);

                    //bind form backing object to datasource
                    $this->bindNodeToActionDatasource($node);
                }

                //re-throw validationexception, which shows form view
                throw new ValidationException($this->errors);
            }

            $this->Session->setFlashAttribute('saved', true);

            if ($this->saveButtonPushed())
                //redirect to list (action_success_view)
                return new View($this->successView());

            elseif($this->saveAndContinueButtonPushed())
                //redirect to edit (action_continue_view)
                return new View($this->continueView(), array('slug'=> $node->getSlug()));

            elseif($this->saveAndNewButtonPushed())
                // redirect to new edit (action_new_view)
                return new View($this->newView(true), array('newslug'=> $node->getSlug()));

        }

        throw new Exception("unsupported button for this action");
    }
1371358
public function addResponse(RequestInterface $request, ResponseInterface $response): self
    {
        $new = clone $this;
        $new->responses->attach($request, $response);

        return $new;
    }
794717
public function add()
    {
        $user = $this->Users->newEntity();

        if ($this->request->is('post')) {
            $user = $this->Users->patchEntity($user, $this->request->getData());

            if ($this->Users->save($user)) {
                $this->Flash->success(I18N_OPERATION_OK);

                return $this->redirect(['action' => 'index']);
            }

            $this->Flash->error(I18N_OPERATION_NOT_OK);
        }

        $this->set(compact('user'));
    }
385139
public function addResource(ResourceInterface $resource, $name = null) {
		if ($name === null) {
			$this->resources[] = $resource;
			
			return $this;
		}
		
		$this->resources[$name] = $resource;
		
		return $this;
	}
1084493
public function add()
    {
        /** @var Language $language */
        $language = $this->Languages->newEntity();
        if ($this->request->is('post') && !empty($this->request->data)) {
            $this->Languages->patchEntity($language, $this->request->data);
            if ($this->Languages->save($language)) {
                $this->Flash->success(__d('wasabi_core', 'The language <strong>{0}</strong> has been created.', $language->name));
                $this->redirect(['action' => 'index']);
                return;
            } else {
                $this->Flash->error($this->formErrorMessage);
            }
        }
        $this->set('language', $language);
    }
729454
public function add() {
		$cell = $this->Cells->newEntity($this->request->data);
		if ($this->request->is('post')) {
			if ($this->Cells->save($cell)) {
				$this->Flash->success('The cell has been saved.');
				return $this->redirect(['action' => 'index']);
			} else {
				$this->Flash->error('The cell could not be saved. Please, try again.');
			}
		}
		$this->set(compact('cell'));
	}
1193908
public function addAction()
    {
        $isPosted = $this->request->getPost('doCreate');
        
        if (!$isPosted) {
            $this->response->redirect($this->request->getPost('redirect'));
        }

        $comment = [
            'content'   => $this->request->getPost('content'),
            'name'      => $this->request->getPost('name'),
            'web'       => $this->request->getPost('web'),
            'mail'      => $this->request->getPost('mail'),
            'timestamp' => time(),
            'ip'        => $this->request->getServer('REMOTE_ADDR'),
        ];

        $comments = new \Phpmvc\Comment\CommentsInSession();
        $comments->setDI($this->di);

        $comments->add($comment);

        $this->response->redirect($this->request->getPost('redirect'));
    }
446394
public function add()
    {
        $user = $this->Users->newEntity();

        $user->accessible('role_id', true); // the role_id field should be accessible
        $user->accessible('active', true); // the active field should be accessible
        $user->accessible('send_mail', true); // checkbox to send an e-mail

        $roles = $this->Users->Roles->find('list');

        if ($this->request->is('post')) {
            $user = $this->Users->patchEntity($user, $this->request->data);

            if (!$user->get('active')) {
                $user->set('activation_key', $this->Users->generateActivationKey());
            }

            if ($this->Users->save($user)) {
                // firing an event: afterRegister
                $_event = new Event('Controller.Users.afterRegister', $this, [
                    'user' => $user,
                    'sendMail' => $user->send_mail
                ]);
                $this->eventManager()->dispatch($_event);
                $this->Flash->success(__('The user has been saved.'));
                return $this->redirect(['action' => 'index']);
            } else {
                $this->Flash->error(__('The user could not be saved. Please, try again.'));
            }
        }

        $customFields = Hash::normalize(Configure::read('CM.UserFields'));

        $this->set(compact('user', 'roles', 'customFields'));

        $this->render(Configure::read('CM.AdminUserViews.add'));
    }
741981
public function add()
    {
        $this->loadModel('User.Roles');
        $role = $this->Roles->newEntity();

        if ($this->request->data()) {
            $role = $this->Roles->patchEntity($role, $this->request->data(), ['fieldList' => 'name']);
            if ($this->Roles->save($role)) {
                $this->Flash->success(__d('user', 'Role successfully created.'));
            } else {
                $this->Flash->danger(__d('user', 'Role could not be created.'));
            }
        }

        $this->title(__d('user', 'Define New Role'));
        $this->set(compact('role'));
        $this->Breadcrumb
            ->push('/admin/user/manage')
            ->push(__d('user', 'Roles'), ['plugin' => 'User', 'controller' => 'roles', 'action' => 'index'])
            ->push(__d('user', 'Add new role'), '');
    }
663758
public function add()
    {
        $this->loadModel('Content.ContentTypes');
        $this->loadModel('User.Roles');
        $type = $this->ContentTypes->newEntity();

        if ($this->request->data()) {
            $type = $this->ContentTypes->patchEntity($type, $this->request->data());
            $errors = $type->errors();
            $success = empty($errors);

            if ($success) {
                $success = $this->ContentTypes->save($type);
                if ($success) {
                    $this->Flash->success(__d('content', 'Content type created, now attach some fields.'));
                    $this->redirect(['plugin' => 'Content', 'controller' => 'fields', 'type' => $type->slug]);
                }
            }

            if (!$success) {
                $this->Flash->danger(__d('content', 'Content type could not be created, check your information.'));
            }
        }

        $roles = $this->Roles->find('list');
        $this->title(__d('content', 'Define New Content Type'));
        $this->set(compact('type', 'roles'));
        $this->set('languages', LocaleToolbox::languagesList());
        $this->Breadcrumb
            ->push('/admin/content/manage')
            ->push(__d('content', 'Content Types'), '/admin/content/types')
            ->push(__d('content', 'Creating Content Type'), '#');
    }
1168647
public function createAction()
    {
        // Check current user authorization
        if (null !== $response = $this->checkAuth(self::CONTROLLER_CHECK_RESOURCE, Dealer::getModuleCode(),
                AccessManager::CREATE)
        ) {
            return $response;
        }

        // Create the Creation Form
        $creationForm = $this->getCreationForm($this->getRequest());

        $con = Propel::getConnection();
        $con->beginTransaction();

        try {
            // Check the form against constraints violations
            $form = $this->validateForm($creationForm, "POST");
            // Get the form field values
            $data = $form->getData();

            if (empty($data["day"])) {
                $dataAM = $this->formatData($data);
                $dataPM = $this->formatData($data, 'PM');

                if ($this->hasNullDate($dataAM) && $this->hasNullDate($dataPM)) {
                    $this->getService()->createFromArray($dataAM, $this->getCurrentEditionLocale());
                } else {
                    if (!$this->hasNullDate($dataAM)) {
                        $this->getService()->createFromArray($dataAM, $this->getCurrentEditionLocale());
                    }
                    if (!$this->hasNullDate($dataPM)) {
                        $this->getService()->createFromArray($dataPM, $this->getCurrentEditionLocale());
                    }
                }
            } else {
                foreach ($data["day"] as $day) {
                    $currentData = $data;
                    $currentData["day"] = $day;
                    $dataAM = $this->formatData($currentData);
                    $dataPM = $this->formatData($currentData, 'PM');

                    if ($this->hasNullDate($dataAM) && $this->hasNullDate($dataPM)) {
                        $this->getService()->createFromArray($dataAM, $this->getCurrentEditionLocale());
                    } else {
                        if (!$this->hasNullDate($dataAM)) {
                            $this->getService()->createFromArray($dataAM, $this->getCurrentEditionLocale());
                        }
                        if (!$this->hasNullDate($dataPM)) {
                            $this->getService()->createFromArray($dataPM, $this->getCurrentEditionLocale());
                        }
                    }
                }
            }


            // Substitute _ID_ in the URL with the ID of the created object
            $successUrl = $creationForm->getSuccessUrl();

            $con->commit();

            // Redirect to the success URL
            return $this->generateRedirect($successUrl);
        } catch (FormValidationException $ex) {
            $con->rollBack();
            // Form cannot be validated
            $error_msg = $this->createStandardFormValidationErrorMessage($ex);
        } catch (\Exception $ex) {
            $con->rollBack();
            // Any other error
            $error_msg = $ex->getMessage();
        }
        if (false !== $error_msg) {
            $this->setupFormErrorContext(
                $this->getTranslator()->trans("%obj creation", ['%obj' => static::CONTROLLER_ENTITY_NAME]),
                $error_msg,
                $creationForm,
                $ex
            );

            // At this point, the form has error, and should be redisplayed.
            return $this->generateErrorRedirect($creationForm);
        }
    }
183894
def add(self, resource, replace=False):
        """"""
        uri = resource.uri
        if (uri in self and not replace):
            raise ResourceSetDupeError(
                "Attempt to add resource already in this set")
        self[uri] = resource
87277
public function add() {
        $user = $this->Users->newEntity();
        if ($this->request->is('post')) {
            $user = $this->Users->patchEntity($user, $this->request->data);
            if ($this->Users->save($user)) {
                $this->Flash->success(__('The user has been saved.'));
                return $this->redirect(['action' => 'index']);
            } else {
                $this->Flash->error(__('The user could not be saved. Please, try again.'));
            }
        }
        $this->set(compact('user'));
        $this->set('_serialize', ['user']);
        $this->filteredSelectOptions();
    }