我是symfony的新手,并且已经按照这个了不起的教程来使用doctrine通过控制台使用命令行来设置我的包和实体。
http://symfony.com/blog/symfony2-getting-easier-interactive-generators
唯一的问题是我设置的类有隐藏字段。例如,创建日期和更新日期。这只是我的记录,所以我可以看到人们是否做过他们不应该做的事情。
唯一的问题是它们正在前端显示,我不知道如何隐藏它们,而不重写生成的代码并逐个添加字段。
这是控制器中的功能
public function createAction(Request $request)
{
$entity = new Client();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('client_show', array('id' => $entity->getId())));
}
return $this->render('AcmeClientMoodBundle:Client:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
/**
* Creates a form to create a Client entity.
*
* @param Client $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createCreateForm(Client $entity)
{
$form = $this->createForm(new ClientType(), $entity, array(
'action' => $this->generateUrl('client_create'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
}
这是实体/类
namespace Acme\ClientMoodBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* Client
*/
class Client
{
/**
* @var integer
*/
private $id;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $logo;
/**
* @var integer
*/
private $moodId;
/**
* @var integer
*/
private $projectManagerId;
/**
* @var \DateTime
*/
private $created;
/**
* @var \DateTime
*/
private $updated;
/**
* @var integer
*/
private $active;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Client
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set logo
*
* @param string $logo
* @return Client
*/
public function setLogo($logo)
{
$this->logo = $logo;
return $this;
}
/**
* Get logo
*
* @return string
*/
public function getLogo()
{
return $this->logo;
}
/**
* Set moodId
*
* @param integer $moodId
* @return Client
*/
public function setMoodId($moodId)
{
$this->moodId = $moodId;
return $this;
}
/**
* Get moodId
*
* @return integer
*/
public function getMoodId()
{
return $this->moodId;
}
/**
* Set projectManagerId
*
* @param integer $projectManagerId
* @return Client
*/
public function setProjectManagerId($projectManagerId)
{
$this->projectManagerId = $projectManagerId;
return $this;
}
/**
* Get projectManagerId
*
* @return integer
*/
public function getProjectManagerId()
{
return $this->projectManagerId;
}
/**
* Set created
*
* @param \DateTime $created
* @return Client
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* @return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated
*
* @param \DateTime $updated
* @return Client
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated
*
* @return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Set active
*
* @param integer $active
* @return Client
*/
public function setActive($active)
{
$this->active = $active;
return $this;
}
实现这一目标的最佳方法是什么?
答案 0 :(得分:2)
您应该查看您的班级ClientType
并删除您不想要的字段。
字段创建如下:
$builder->add('created');
删除此行。