Symfony Hidden fields



我是symfony的新手,并且按照这个惊人的教程通过控制台使用原则使用命令行设置我的捆绑包和实体。

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 SymfonyComponentFormForm 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 AcmeClientMoodBundleEntity;
use DoctrineORMMapping as ORM;
use SymfonyComponentValidatorConstraints as Assert;
use SymfonyBridgeDoctrineValidatorConstraintsUniqueEntity;
/**
 * 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;
    }

实现这一目标的最佳方法是什么?

您应该

查看您的类ClientType并删除您不需要的字段。

字段创建如下所示:

$builder->add('created');

删除此行。

相关内容

  • 没有找到相关文章

最新更新