0

我正在尝试在我的 Symfony2 应用程序中使用 JEditable 插件。PYS实体是电影和电视节目实体;然后我有UsuarioCritica实体。我想用插件管理用户的批评者。我分析了越来越多的例子,但我无法让它发挥作用。值(在本例中为critic 的标题)在模板中更新,但不在数据库中;当我刷新浏览器时,会出现旧值。

错误:

在此处输入图像描述

这是我的 JS:

$('.edit').editable(function(value, settings) { 
        var data = {};
        data[this.id] = value;
        console.log(path);
        console.log(data);
        $.post(path, data);
            return(value);
    }, {
        indicator : 'Saving...',
        tooltip   : 'Click to edit...'
    });

这是路线:

critica_ajax:
    locales: { es: "/gestion-critica/{pysStr}/", en: "/manage-critic/{pysStr}/" }
    defaults: { _controller: UsuarioBundle:Default:gestionarCritica }

这是控制器:

public function gestionarCriticaAction($pysStr)
{
    $em = $this->getDoctrine()->getManager();
    $pys = $em->getRepository('PYSBundle:Pys')->findPys($pysStr);
    $usuario = $this->get('security.context')->getToken()->getUser();
    $critica = $em->getRepository('UsuarioBundle:Usuario')->findCritica($usuario, $pys);

    if(!$critica) 
    {
        $critica = new Critica($usuario, $pys);
    }

    $criTitulo = $this->request->get('value');
    $critica->setCriTitulo($criTitulo);

    $critica->setCriContenido($criContenido);
    $critica->setCriFecha(new \DateTime("now"));

    $em->persist($critica); 

    $em->flush();

    return new Response($criTitulo);
}

树枝模板:

<h2 class="edit">{{ critica.criTitulo }}</h2>
<script>
    var path = "{{ path('critica_ajax', { 'pysStr': pelicula.pysStr}) }}";
</script>

编辑(Symfony 的回归)

Notice: Undefined property: Filmboot\UsuarioBundle\Controller\DefaultController::$request
in C:\Programming\xampp\htdocs\filmboot\src\Filmboot\UsuarioBundle\Controller\DefaultController.php line 236

THIS IS THE LINE 236: $criTitulo = $this->request->get('value');

at ErrorHandler ->handle ('8', 'Undefined property: Filmboot\UsuarioBundle\Controller\DefaultController::$request', 'C:\Programming\xampp\htdocs\filmboot\src\Filmboot\UsuarioBundle\Controller\DefaultController.php', '236', array('pysStr' => 'machete', 'em' => object(EntityManager), 'pys' => object(Pys), 'usuario' => object(Usuario), 'critica' => object(Critica))) 
    in C:\Programming\xampp\htdocs\filmboot\src\Filmboot\UsuarioBundle\Controller\DefaultController.php at line 236   +
    at DefaultController ->gestionarCriticaAction ('machete')
    at call_user_func_array (array(object(DefaultController), 'gestionarCriticaAction'), array('machete')) 
    in C:\Programming\xampp\htdocs\filmboot\app\bootstrap.php.cache at line 1003   +
    at HttpKernel ->handleRaw (object(Request), '1') 
    in C:\Programming\xampp\htdocs\filmboot\app\bootstrap.php.cache at line 977   +
    at HttpKernel ->handle (object(Request), '1', true) 
    in C:\Programming\xampp\htdocs\filmboot\app\bootstrap.php.cache at line 1103   +
    at ContainerAwareHttpKernel ->handle (object(Request), '1', true) 
    in C:\Programming\xampp\htdocs\filmboot\app\bootstrap.php.cache at line 413   +
    at Kernel ->handle (object(Request)) 
    in C:\Programming\xampp\htdocs\filmboot\web\app_dev.php at line 26   +
4

1 回答 1

0

你需要得到这样的请求:

$request = $this->getRequest();

代替

$request = $this->request;

请求是使用方法返回的,它不是类属性

于 2013-07-31T15:35:59.663 回答