<?php namespace Common\Model; use Common\Constraint as AppAssert; use Symfony\Component\Validator\Constraints as Assert; use Troytft\DataMapperBundle\Annotation\DataMapper; class PostsFilter { /** * @DataMapper(type="string") */ protected $query; /** * @DataMapper(type="entity", options={"class": "CommonBundle:City"}) * @Assert\NotBlank */ protected $city; /** * @return mixed */ public function getCity() { return $this->city; } /** * @param mixed $value */ public function setCity($value) { $this->city = $value; return $this; } /** * @return string */ public function getQuery() { return $this->query; } /** * @param string $value */ public function setQuery($value) { $this->query = $value; return $this; } }
/** @var Request $request */ $request = $this->get('request'); $data = $request->getRealMethod() == 'GET' ? $request->query->all() : $request->request->all(); /** @var DataMapperManager $manager */ $manager = $this->get('data_mapper.manager'); $model = $manager ->setGroups($groups) ->setValidationGroups($validationGroups) ->setIsClearMissing($clearMissing) ->setIsValidate(true) ->handle($model, $data);
public function createAction() { $user = $this->getUser(); $entity = $this->save($this->handleRequest(new Common\Entity\Blog\Post($this->getUser()))); $this->getNotificationManager()->notifyModerators($entity); return $entity; }
Source: https://habr.com/ru/post/281875/
All Articles