getDoctrine()在FOSUserBundle symfony2中不起作用 - php

我需要创建一个状态下拉菜单,以便一旦我从country drop_down中选择国家,那么该国家的状态drop_down应该使用Ajax出现。
错误后出现错误。

尝试调用类“ FOS \ UserBundle \ Controller \ RegistrationController”的名为“ getDoctrine”的未定义方法

AJAX被调用,国家/地区的ID被传递给控制器​​,主要问题是getDoctrine函数。
这是我的控制器。

我是symfony的新手,请帮助我。

public function getStateAction(Request $request)
    {               
            $em1 = $this->getDoctrine()->getManager();
            $data = $request->request->all();   

            $countryId = $data['id'];
            $repository = $em->getRepository('FOSUserBundle:State');
            $query = $repository->createQueryBuilder('p');
            $query->where('p.country ='.$countryId);
            $query->orderBy('p.id', 'ASC');
            $stateList = $query->getQuery()->getResult();
            //print_r($stateList); die;
    }

这是我的ajax

$(document).ready(function(){   
    $("#fos_user_registration_form_country_id").change(function(){
    var countryId = $(this).val();
             if(countryId!=0){
               $.ajax({
               type: "POST",
               url: "{{ path('fos_user_registration_country') }}",
               data: {id: countryId},
               cache: false,
               success: function(result){
               ("#fos_user_registration_form_state_id").append(result);
             }
           });
        }
    });
});

参考方案

您是否尝试过:

public function getStateAction(Request $request)
{   
    $em1 = $this->container->get('doctrine')->getManager();

    /.../
}

getDoctrine()是类Symfony\Bundle\FrameworkBundle\Controller\Controller的方法,该方法未从FOS\UserBundle\Controller\RegistrationController扩展

PHP strtotime困境 - php

有人可以解释为什么这在我的服务器上输出为true吗?date_default_timezone_set('Europe/Bucharest'); var_dump( strtotime('29.03.2015 03:00', time()) === strtotime('29.03.2015 04:00�…

PHP-全局变量的性能和内存问题 - php

假设情况:我在php中运行一个复杂的站点,并且我使用了很多全局变量。我可以将变量存储在现有的全局范围内,例如$_REQUEST['userInfo'],$_REQUEST['foo']和$_REQUEST['bar']等,然后将许多不同的内容放入请求范围内(这将是适当的用法,因为这些数据指的是要求自…

php-casperjs获取内部文本 - php

我正在为casperjs使用php包装器-https://github.com/alwex/php-casperjs我正在网上自动化一些重复的工作,我需要访问一个项目的innerText,但是我尚不清楚如何从casperjs浏览器访问dom。我认为在js中我会var arr = document.querySelector('label.input…

PHP-将日期插入日期时间字段 - php

我已在数据库中使用datetime字段存储日期,使用PHP将“今天的日期”插入该字段的正确方法是什么?干杯, 参考方案 我认为您可以使用php date()函数

PHP-从最后一个循环中删除逗号 - php

我在循环时有一个PHP,如果是最后一个循环,我想从,中删除​​最后一个逗号echo '],'; while($ltr = mysql_fetch_array($lt)){ echo '['; echo $ltr['days']. ' ,'. $ltr['name…