我有一个文件夹ProjectFolder
,其中包含子文件夹Mobile
和模板indexMobile.html.twig
。使用注解在子文件夹中访问模板
AppBundle
| Resources
| views
| ProjectFolder
| Mobile
- indexMobile.html.twig
| someView.html.twig
| someView.html.twig
| someView.html.twig
在我的控制器中我试着用各种recommandation与@Template doc和@route doc
访问它,但是我不同的方法没有找到我已创建的模板,它一直要求我在views
创建一个模板,而不是直接Mobile
子文件夹。
class ProjectFolderController extends Controller
/**
* @Route("@Mobile/indexMobile")
* @Method({"GET", "POST"})
* @Template
*/
public function indexMobileAction()
{
return[];
}
-
class ProjectFolderController extends Controller
/**
* @Route("/Mobile/indexMobile")
* @Method({"GET", "POST"})
* @Template
*/
public function indexMobileAction()
{
return[];
}
-
class ProjectFolderController extends Controller
/**
* @Route("Mobile", name="indexMobile")
* @Method({"GET", "POST"})
* @Template
*/
public function indexMobileAction()
{
return[];
}
其实这个工作,但这不是我应该使用的方式:
class ProjectFolderController extends Controller
/**
* @Route("/mobile/index")
* @Method({"GET", "POST"})
* @Template("@ProjectFolder/Mobile/index.html.twig")
*/
public function indexMobileAction()
{
return[];
}
编辑
一些尝试后,我发现这一点:
class ProjectFolderController extends Controller
/**
* @Route("@ProjectFolder/Mobile", name="/mobile/index")
* @Method({"GET", "POST"})
* @Template
*/
public function indexMobileAction()
{
return[];
}
但我得到这个错误:No route found for "GET/mobile/index"
感谢您的时间,解释为什么@Template不支持子目录。现在更清晰。 –