я пытаюсь вставить данные в базу данных, но отправленные формы ничего не делают.
это мой сервис-менеджер:
class AutosManager
{
/**
* Entity manager.
* @var Doctrine\ORM\EntityManager;
*/
private $entityManager;
/**
* Constructor.
*/
public function __construct($entityManager)
{
$this->entityManager = $entityManager;
}
public function addNewAutos($data)
{
$autos = new Autos();
$autos->setTitle($data['title']);
$autos->setDescription($data['description']);
$currentDate = date('Y-m-d H:i:s');
$autos->setDateCreated($currentDate);
$this->entityManager->persist($autos);
$this->entityManager->flush();
}
это мой контроллер addAction
public function addAction()
{
// Create the form.
$form = new PostForm();
if ($this->getRequest()->isPost()) {
// Get POST data.
$data = $this->params()->fromPost();
// Fill form with data.
$form->setData($data);
if ($form->isValid()) {
// Get validated form data.
$data = $form->getData();
$this->AutosManager->addNewAutos($data);
return $this->redirect()->toRoute('retrieve');
}
}
return new ViewModel([
'form' => $form
]);
}
я могу получить данные из базы данных на страницу индекса, но я не могу добавить. надеюсь найти решение.
это мой автомобильный объект
namespace Retrieve\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity(repositoryClass="\Retrieve\Repository\AutosRepository")
* @ORM\Table(name="auto")
*/
class Autos
{
/**
* @ORM\Id
* @ORM\Column(name="id")
* @ORM\GeneratedValue
*/
protected $id;
/**
* @ORM\Column(name="title")
*/
protected $title;
/**
* @ORM\Column(name="description")
*/
protected $description;
/**
* @ORM\Column(name="featured")
*/
protected $featured;
/**
* @ORM\Column(name="date_created")
*/
protected $dateCreated;
/**
* Returns ID of this post.
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Sets ID of this post.
* @param int $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* Returns title.
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Sets title.
* @param string $title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Returns featured.
* @return integer
*/
public function getFeatured()
{
return $this->featured;
}
/**
* Sets featured.
* @param integer $featured
*/
public function setFeatured($featured)
{
$this->featured = $featured;
}
/**
* Returns post description.
*/
public function getDescription()
{
return $this->description;
}
/**
* Sets post description.
* @param type $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* Returns the date when this post was created.
* @return string
*/
public function getDateCreated()
{
return $this->dateCreated;
}
/**
* Sets the date when this post was created.
* @param string $dateCreated
*/
public function setDateCreated($dateCreated)
{
$this->dateCreated = $dateCreated;
}
}
надеюсь, что это поможет найти решение.