Php symfony模板&x27;render()中的名称
我正在尝试创建登录页面,我只想测试我是否工作,但我遇到了模板位置的问题,所以这是我的代码Php symfony模板&x27;render()中的名称,php,symfony,Php,Symfony,我正在尝试创建登录页面,我只想测试我是否工作,但我遇到了模板位置的问题,所以这是我的代码 namespace Login\loginBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class LoginController extends Controller { public function loginAction() { $username="us
namespace Login\loginBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class LoginController extends Controller
{
public function loginAction()
{
$username="username";
$password="password";
$em=$this->getDoctrine()->getEntityManager();
$repository=$em->getRepository('Login\loginBundle\Entity\Login\Utilisateur');
$user=$repository->findOneBy(array('username'=>$username,'password'=>$password));
if($user){
return $this->render('Login\loginBundle\Resources\views\Default\index.html.twig',array('name'=>$user->getNom()));
}
else{
return $this->render('Login\loginBundle\Resources\views\Default\index.html.twig',array('name'=>'login failed'));
}
}
这是我的模板的位置
Login\loginBundle\Resources\views\Default\index.html.twig
这就是我得到的错误:
Unable to find template "Login\loginBundle:Default:index.html.twig".
500 Internal Server Error - InvalidArgumentException
3 linked Exceptions:
Twig_Error_Loader »
InvalidArgumentException »
InvalidArgumentException »
[4/4] InvalidArgumentException: Unable to find template "Login\loginBundle:Default:index.html.twig". +
[3/4] Twig_Error_Loader: Unable to find template "Login\loginBundle:Default:index.html.twig". +
[2/4] InvalidArgumentException: Template name "Login/loginBundle:Default:index.html.twig" is not valid. +
[1/4] InvalidArgumentException: Bundle "Login/loginBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file? +
感谢您的帮助如:
模板字符串的命名不正确。 在您的情况下,应如下所示:
$this->render('@Login/loginBundle/Default/index.html.twig');
我建议您使用带有Symfony2插件的像PHPStorm这样的IDE来利用intellisense。
这是工作,但它不会引导我进入我想要的页面我访问了其他页面可能你正在重定向到
app/
资源,你能检查一下吗?谢谢,它工作正常,但我应该使用loginBundle而不是LoginloginBundle,因为我更改了它的名称
$this->render('@Login/loginBundle/Default/index.html.twig');
$this->render('LoginloginBundle:Default:index.html.twig');