我使用JEditable插件时POST 500(内部服务器错误)

时间:2013-07-31 08:05:10

标签: javascript jquery symfony jeditable

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

错误:

enter image description here

这是我的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);
}

Twig模板:

<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   +

1 个答案:

答案 0 :(得分:0)

你需要得到这样的请求:

$request = $this->getRequest();

而不是

$request = $this->request;

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