我手动创建了Document,然后尝试使用persist
保存数据。它向我显示以下错误。
The class 'Kdm\\SettingBundle\\Document\\Discount' was not found in the chain configured namespaces FOS\\UserBundle\\Entity, Ivory\\GoogleMapBundle\\Entity at
/var/www/project/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:37)"}
这是我的文档文件Discount.php
<?php
namespace Kdm\SettingBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Discount
* @MongoDB\Document(repositoryClass="Kdm\SettingBundle\Repository\SettingRepository")
*/
class Discount
{
/**
* @MongoDB\Id(strategy="auto")
*/
protected $id;
/**
* @MongoDB\Field(type="integer")
*/
protected $value;
/**
* Get id
*
* @return string $id
*/
public function getId()
{
return $this->id;
}
/**
* @param integer $value
*/
public function setValue($value)
{
$this->value = $value;
}
/**
* @return integer
*/
public function getValue()
{
return $this->value;
}
}
这是我的SettingController.php
<?php
namespace Kdm\SettingBundle\Controller;
use Kdm\KdmBundle\Controller\RefController as KdmController;
use Kdm\SettingBundle\Document\Discount as Setting;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
/**
* @Route("/setting")
*/
class SettingController extends KdmController
{
/**
* Constructor
*/
public function __construct()
{
parent::__construct('Kdm', 'Setting', 'setting','Discount');
}
/**
* @Route
* (
* path="/",
* name="kdm_setting"
* )
* @Template("::KdmSetting/Front/index.html.twig")
*/
public function indexAction()
{
$setting = new Setting();
$setting->setValue('5');
$em = $this->getDoctrine()->getManager();
$em->persist($setting);
$em->flush();
$form = $this->createFormBuilder($setting)
->add('value','integer')
->add('save','submit')
->getForm();
return array(
'form' => $form->createView()
);
}
}
自最近两天以来,我一直尝试解决此错误:(您能帮忙吗?