Php symfony用户访问网页的权限
如果用户的数据库中有某个值,Php symfony用户访问网页的权限,php,symfony,twig,webpage,Php,Symfony,Twig,Webpage,如果用户的数据库中有某个值,$row['GameId'],我想让用户可以使用网页上的某个细枝输入表单 所以我试着为这样的代码编写if语句 $sqlo = $conn->query("SELECT * FROM user WHERE username='$tuser'"); while ($row = $sqlo->fetch(PDO::FETCH_ASSOC)) { $gid = $row['GameId']; if($gid == 0 ){
$row['GameId'],我想让用户可以使用网页上的某个细枝输入表单代码>
所以我试着为这样的代码编写if语句
$sqlo = $conn->query("SELECT * FROM user WHERE username='$tuser'");
while ($row = $sqlo->fetch(PDO::FETCH_ASSOC))
{
$gid = $row['GameId'];
if($gid == 0 ){
$investor = $this->getDoctrine()->getRepository('AppBundle:User')->findOneBy(array('id' => $user->getId()));
$MatchP = $investor->getMatchP();
$form = $this->createForm(new TaskType(), $investor);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
if(!empty($form->get('MatchP')->getData())){
$investor->setMatchP($form->get('MatchP')->getData());
}
else{
$investor->setMatchP($MatchP);
}
$em = $this->getDoctrine()->getManager();
$em->persist($investor);
$em->flush();
$session = $this->getRequest()->getSession();
/**
* @Route("/siteblog_homepage/")
*/
return $this->redirectToRoute('siteblog_homepage');
}
}
else{
?> your value are not the right one to access to this page <?
}
return $this->render('siteblogBundle:Default:index.html.twig', array(
'form' => $form->createView(),
));
//}
}
因为这条线
'form' => $form->createView(),
那么如何以wright方式保护此页面呢?$form仅在if(true)内部可用
下面的代码返回:注意:未定义变量:a
<?php
if("2"=="1")
{
$a = "10";
}
echo $a;
?>
在if条件外定义$form。$form仅在if内可用(true)
下面的代码返回:注意:未定义变量:a
<?php
if("2"=="1")
{
$a = "10";
}
echo $a;
?>
在if条件之外定义$form。首先,您需要从while循环块中获取外部,查看:
第二:
您的代码可以返回0、1或多个表单
while ($row = $sqlo->fetch(PDO::FETCH_ASSOC))
{
$gid = $row['GameId'];
if($gid == 0 ){$form = $this->createForm(new TaskType(), $investor);
/**/}
查看您创建表单的每个循环指令,这样您就不知道最后要生成多少表单,因为我们不知道有多少($gid==0)。
因此,我建议您将这些形式呈现给您的视图:
$forms = array();
array_push($forms,$form->createView());
return $this->render('siteblogBundle:Default:index.html.twig', array(
'forms' => $forms));
通过这种方式,您将所有表单推送到一个数组中,然后只需将数组解析到您的细枝文件中:
{% for form in forms %}
{{dump(form)}}
{{form(form)}}
{% endfor %}
希望我能帮上忙。首先,您需要从while循环块中走出去,看看:
第二:
您的代码可以返回0、1或多个表单
while ($row = $sqlo->fetch(PDO::FETCH_ASSOC))
{
$gid = $row['GameId'];
if($gid == 0 ){$form = $this->createForm(new TaskType(), $investor);
/**/}
查看您创建表单的每个循环指令,这样您就不知道最后要生成多少表单,因为我们不知道有多少($gid==0)。
因此,我建议您将这些形式呈现给您的视图:
$forms = array();
array_push($forms,$form->createView());
return $this->render('siteblogBundle:Default:index.html.twig', array(
'forms' => $forms));
通过这种方式,您将所有表单推送到一个数组中,然后只需将数组解析到您的细枝文件中:
{% for form in forms %}
{{dump(form)}}
{{form(form)}}
{% endfor %}
但愿我能帮上忙。在else
部分添加重定向,比如return$this->redirect('yourRoute')代码>@Hokusai谢谢你worked@Bhs是的,我使用了重定向在else
部分中放置重定向,比如return$this->redirect('yourRoute')代码>@Hokusai谢谢你worked@Bhs是的,我用重定向