【问题标题】:run a command line from a symfony function从 symfony 函数运行命令行
【发布时间】:2018-05-06 21:22:52
【问题描述】:

我喜欢从 symfony 函数运行:php sendnotifications.php(路径:C:\wamp64\bin\php\php5.6.25\php.exe sendnotifications.php)

public function reserverHebAction(Request $request,$idHebergement)
{
    $em = $this->getDoctrine()->getManager();
    $ReservationHebergement = new ReservationHebergement();
    $form = $this->createForm(ReserverType::class, $ReservationHebergement);


    $hebergement=$em->getRepository('govoyagereverseBundle:Hebergement')
        ->find($idHebergement);

    if ($form->handleRequest($request)->isValid() ){
        $hebergement->setDisponibilite($hebergement->getDisponibilite() ==0);
        $user = $this->container->get('security.token_storage')->getToken()->getUser();
        $em = $this->getDoctrine()->getManager();
        $em->persist($hebergement);//insert into model
        $em->flush();//execution de la requete

        $ReservationHebergement->setNomUtilisateurH($user);
        $ReservationHebergement->setIdhebergement($idHebergement);

        $em->persist($ReservationHebergement);
        $em->flush();
        //************sms-***************************************
        /**********I I NEED TO EXCUTE IT HERE **************
        //*******sms-*****************************

        return $this->redirectToRoute('rechercheHeb');
    }
    return $this->render(
        '@govoyagegestionHebergementAdmin/hebergement/reserverHeb.html.twig',
        array('f2' => $form->createView())
    );
}

【问题讨论】:

    标签: php html css symfony


    【解决方案1】:

    您应该能够使用execshell_exec 方法来执行您具体要求(here's an answer discussing the difference) 的操作,但我建议您导入您需要的任何功能并运行它。

    【讨论】:

    • Symfony 也有一个Process component 来处理这类事情。可能是矫枉过正。
    • 同意,进程是一个更好的解决方案,但无论如何你都不应该为php.exe phpfile.php运行进程
    • 我添加 ------ $process = new Process('/wamp64/bin/php sendnotifications.php'); $process->run();----- 还是不行
    • 他找不到声明去sendnotifications.php和wamp64是正常的吗?
    • 错误消息通常使事情更容易调试。但我总是喜欢挑战。我怀疑 php 可执行文件不知道 sendnotifications.php 在哪里。
    猜你喜欢
    • 1970-01-01
    • 2011-04-28
    • 2021-10-22
    • 1970-01-01
    • 2014-11-27
    • 2017-05-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多