警告:preg_match()期望参数2为字符串,对象为ERROR Symfony 3

时间:2016-12-01 01:43:05

标签: php symfony1 symfony

发生此错误时,我正在执行简单的更新操作。更新操作已完成,但当我尝试返回以查看页面上的修改时,我收到以下错误:

  

警告:preg_match()期望参数2为字符串,对象为

这是我的Twig代码:

public class MyInitializer implements WebApplicationInitializer {

@Override
public void onStartup(ServletContext servletContext) {

    //Clear out reference to applicationContext.xml
    servletContext.setInitParameter("contextConfigLocation", "");

    // Create the 'root' Spring application context
    AnnotationConfigWebApplicationContext rootContext =
            new AnnotationConfigWebApplicationContext();
    rootContext.register(MySpringRootConfiguration.class);

    // Manage the lifecycle of the root application context
    servletContext.addListener(new ContextLoaderListener(rootContext));

    //Add jersey or any other servlets
    ServletContainer jerseyServlet = new ServletContainer(new RestApplication());
    Dynamic servlet = servletContext.addServlet("jersey-servlet", jerseyServlet);
    servlet.addMapping("/api/*");
    servlet.setLoadOnStartup(1);
}
}

这是我的行动代码:

<form class="form-horizontal" method="post" action="{{ path('Update_comment',{'idc':comment.id}) }}">
    <div class="control-group">
         <label class="control-label" for="inputPassword">New Comment <sup>*</sup></label>
         <div class="controls">
              <textarea name="contenu" cols="2" rows="20"></textarea>
         </div>
    </div>
    <div class="control-group">
         <div class="controls">
              <button type="submit" class="btn btn-success">
                    <i class=" icon-pencil"></i>Edit
              </button>
         </div>
    </div>
</form>

这些是我路由的配置:

public function UpdateCommentAction($idc){
    $em = $this->getDoctrine()->getManager();

    $cmt = $em->getRepository('MyAppUserBundle:PostComment')->find($idc);
    $idPost=$cmt->getIdPost();

    if ($cmt != null) {
        if (isset($_POST['contenu'])) {
            $cmt->setContenu($_POST['contenu']);

            $em->flush();
        }
    }

    return $this->redirectToRoute("get_view_post", array('id' => $idPost));
}

我不知道问题出在哪里,尤其是更新操作正在运行。

1 个答案:

答案 0 :(得分:1)

您可以从Symfony项目的根目录中的命令行运行它:

php bin/console cache:clear --env=prod

我怀疑也许你做了改动而且他们仍然被缓存。 除非你有什么别的东西告诉我们?我无法看到该消息来自何处,因为您在任何地方都没有preg_match