私はデータベースにデータを挿入しようとしていますが、送信されたフォームは何もしません。zf3とdoctrineを使ってデータベースにデータを挿入する
これは私のサービス・マネージャである:
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;
}
}
であるが、これは解決策を見つけるのに役立ちます願っています。
エラーログはありますか? 'Entity'、' AutosManager'、 'Controller'のような関連コードを与えることができますか? @DollyAswin。 –
いいえ。エラーログはありません。 – dino
エンティティに問題はないようです。 'AutosManager'に' EntityManager'を渡しましたか? –