0
我正在寻找显示与当前用户(导师)具有相同课程ID的学生列表。自定义查询symfony2
http://snag.gy/VOHJ3.jpg这是我的数据库设计。
<?php
namespace Simple\ProfileBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\HttpFoundation\Request;
class SecurityController extends Controller
{
public function loginAction(Request $request)
{
$session = $request->getSession();
// get the login error if there is one
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
} else {
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
}
return $this->render('SimpleProfileBundle:Security:login.html.twig', array(
// last username entered by the user
'last_username' => $session->get(SecurityContext::LAST_USERNAME),
'error' => $error,
));
}
public function dumpStringAction()
{
$findStudents = $this->getUser()->getCourses();
$results = $this->_em
->createQuery("SELECT * FROM user where")
->getResult();
return $results;
}
return $this->render('SimpleProfileBundle:Security:dumpString.html.twig', array(
'findstudents'=> $findStudents));
}
}
任何人都有任何想法我可以做到这一点?我正在考虑自定义查询,但我不确定如何执行此操作?
干杯
Aah运行SQL查询的日子是4行代码。不再! – Rudie
您也可以仅从控制器执行SQL,但这不是一个好习惯。 – bartek
感谢您的回复,这非常有帮助,当您根据数据库信息找到用户类型时,我将需要在查询中显示多个“where”。例如,它会是course.id = x和role.id = x,可以这样做吗? – user2171245