Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.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_Symfony1_Symfony 2.1_Orangehrm - Fatal编程技术网

Php 在symfony中保存数据库中的新表单字段

Php 在symfony中保存数据库中的新表单字段,php,symfony,symfony1,symfony-2.1,orangehrm,Php,Symfony,Symfony1,Symfony 2.1,Orangehrm,我今天开始做symfony。我必须在表单中添加一个新字段,并将其保存在表中(orange hrm定制)。 我创建了一个新的表单字段注释。我还修改了目标表。当我提交表单时,注释未保存。我想我必须在symfony中进行一些配置,以便在数据库中保存注释。请帮我解决这个问题 编辑:我的代码是 public function execute($request) { $this->form = $this->getForm(); print "<

我今天开始做symfony。我必须在表单中添加一个新字段,并将其保存在表中(orange hrm定制)。 我创建了一个新的表单字段注释。我还修改了目标表。当我提交表单时,注释未保存。我想我必须在symfony中进行一些配置,以便在数据库中保存注释。请帮我解决这个问题

编辑:我的代码是

    public function execute($request) { 

        $this->form = $this->getForm();

        print "<pre>";
    print_r($this->form->getValues());
    print "</pre>";

    //Output shows [comment] => dddd

    $leaveEntitlement = $this->getLeaveEntitlement($this->form->getValues());

    print "<pre>";
    print_r($leaveEntitlement);
    print "</pre>";



    LeaveEntitlement Object
    (
    [_node:protected] => 
    [_id:protected] => Array
    (
        [id] => 1
    )

    [_data:protected] => Array
    (
        [id] => 1
        [emp_number] => 3
        [no_of_days] => 384
        [days_used] => 0.0000
        [leave_type_id] => 2
        [from_date] => 2014-01-01 00:00:00
        [to_date] => 2014-01-31 00:00:00

        [credited_date] => 2014-01-30 00:00:00
        [note] => 
        [entitlement_type] => 1
        [deleted] => 0
        [created_by_id] => 1
        [created_by_name] => Admin
    )

    [_values:protected] => Array
    (
    )


    // It is not showing [comment] => dddd
}
公共函数执行($request){
$this->form=$this->getForm();
打印“”;
class YourController extends Controller
{
    public function executeAction($request)
    {
        $entity = new Comment;
        $form = $this->createForm(new CommentType(), $entity);

            $form->handleRequest($request);

            if ($form->isValid())
            {
                $em = $this->getDoctrine()->getManager(); // this is where it begins
                $em->persist($entity); // it goes on
                $em->flush(); // done!

                return $this->redirect($this->generateUrl('your_next_url'));
            }

            return $this->render('YourBundle:YourDirectory:template.html.twig', array(
                'form' => $form->createView(),
            ));
    }
}
打印($this->form->getValues());
class YourController extends Controller
{
    public function executeAction($request)
    {
        $entity = new Comment;
        $form = $this->createForm(new CommentType(), $entity);

            $form->handleRequest($request);

            if ($form->isValid())
            {
                $em = $this->getDoctrine()->getManager(); // this is where it begins
                $em->persist($entity); // it goes on
                $em->flush(); // done!

                return $this->redirect($this->generateUrl('your_next_url'));
            }

            return $this->render('YourBundle:YourDirectory:template.html.twig', array(
                'form' => $form->createView(),
            ));
    }
}
打印“”;
class YourController extends Controller
{
    public function executeAction($request)
    {
        $entity = new Comment;
        $form = $this->createForm(new CommentType(), $entity);

            $form->handleRequest($request);

            if ($form->isValid())
            {
                $em = $this->getDoctrine()->getManager(); // this is where it begins
                $em->persist($entity); // it goes on
                $em->flush(); // done!

                return $this->redirect($this->generateUrl('your_next_url'));
            }

            return $this->render('YourBundle:YourDirectory:template.html.twig', array(
                'form' => $form->createView(),
            ));
    }
}
//输出显示[注释]=>dddd $leaveAuthentication=$this->getleaveAuthentication($this->form->getValues()); 打印“”;
class YourController extends Controller
{
    public function executeAction($request)
    {
        $entity = new Comment;
        $form = $this->createForm(new CommentType(), $entity);

            $form->handleRequest($request);

            if ($form->isValid())
            {
                $em = $this->getDoctrine()->getManager(); // this is where it begins
                $em->persist($entity); // it goes on
                $em->flush(); // done!

                return $this->redirect($this->generateUrl('your_next_url'));
            }

            return $this->render('YourBundle:YourDirectory:template.html.twig', array(
                'form' => $form->createView(),
            ));
    }
}
印刷费($);
class YourController extends Controller
{
    public function executeAction($request)
    {
        $entity = new Comment;
        $form = $this->createForm(new CommentType(), $entity);

            $form->handleRequest($request);

            if ($form->isValid())
            {
                $em = $this->getDoctrine()->getManager(); // this is where it begins
                $em->persist($entity); // it goes on
                $em->flush(); // done!

                return $this->redirect($this->generateUrl('your_next_url'));
            }

            return $this->render('YourBundle:YourDirectory:template.html.twig', array(
                'form' => $form->createView(),
            ));
    }
}
打印“”;
class YourController extends Controller
{
    public function executeAction($request)
    {
        $entity = new Comment;
        $form = $this->createForm(new CommentType(), $entity);

            $form->handleRequest($request);

            if ($form->isValid())
            {
                $em = $this->getDoctrine()->getManager(); // this is where it begins
                $em->persist($entity); // it goes on
                $em->flush(); // done!

                return $this->redirect($this->generateUrl('your_next_url'));
            }

            return $this->render('YourBundle:YourDirectory:template.html.twig', array(
                'form' => $form->createView(),
            ));
    }
}
离开权利对象 ( [\u节点:受保护]=> [\u id:protected]=>阵列 ( [id]=>1 ) [\u数据:受保护]=>阵列 ( [id]=>1 [emp_编号]=>3 [天数]=>384 [使用天数]=>0.0000 [离开类型\u id]=>2 [起始日期]=>2014-01-01 00:00:00 [截止日期]=>2014-01-31 00:00:00 [日期]=>2014-01-30 00:00:00 [注]=> [权利类型]=>1 [已删除]=>0 [由\u id创建的\u]=>1 [按名称创建]=>管理员 ) [\u值:受保护]=>阵列 ( ) //它没有显示[注释]=>dddd }
这种魔力必须发生在您的控制器中,您必须使用两件事:

您必须调用
$form->handleRequest($request)

您还需要使用
$em->persist($entity)->flush()持久化实体

下面是一个基于代码的示例。这是处理表单时控制器的一部分:


请发布与问题相关的代码。您可以编辑自己的问题,并将其添加到问题正文中。这将有助于我们帮助您。请告诉我们您使用的是哪个版本的symfonyusing@Touki请检查编辑