Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony隐藏字段_Php_Symfony_Doctrine Orm - Fatal编程技术网

Php Symfony隐藏字段

Php Symfony隐藏字段,php,symfony,doctrine-orm,Php,Symfony,Doctrine Orm,我是symfony的新手,并遵循这一惊人的教程,通过控制台使用命令行使用条令来设置我的包和实体 唯一的问题是我设置的类有隐藏字段。例如,创建日期和更新日期。这只是我的记录,所以我可以看看人们是否做了他们不应该做的事情 唯一的问题是它们显示在前端,我不知道如何隐藏它们,而不重写生成的代码并逐个添加字段 以下是控制器中的函数 public function createAction(Request $request) { $entity = new Client(); $form

我是symfony的新手,并遵循这一惊人的教程,通过控制台使用命令行使用条令来设置我的包和实体

唯一的问题是我设置的类有隐藏字段。例如,创建日期和更新日期。这只是我的记录,所以我可以看看人们是否做了他们不应该做的事情

唯一的问题是它们显示在前端,我不知道如何隐藏它们,而不重写生成的代码并逐个添加字段

以下是控制器中的函数

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;
    }

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

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

字段创建如下所示:

$builder->add('created');

删除此行。

Woo这很容易。我爱symfony!感谢您的快速响应。最后一件事是如何将日期变量传递到数据库。例如:在下面的消息中,我需要传递一些东西,比如$date->format('d-m-yh:I:s');'使用参数[“Test”、“\/logo.jpg”、1、1、null、null、true]:在持久化实体之前,必须使用类似于
$entity->setCreated(new\Datetime(“now”)我邀请你阅读。这个例子正是你需要的。