我正在尝试在 symfony3 中进行实验。我试图在谷歌上搜索它,但我没有找到他们明确的答案。这是 symfony 中的默认控制器
class DefaultController extends Controller
{
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
// replace this example code with whatever you need
return $this->render('default/index.html.twig', [
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
]);
}
}
如果您看到返回渲染。它将显示默认/index.html.twig来自应用程序/资源/视图/default/index.html.twig我想知道是否可以将我的视图文件夹放在我的 AppBundle 文件夹中?这是我在 AppBundle 中的列表文件夹
AppBundle
-Controller
-Entity
-Form
-Resources
-views
-default
-index.html.twig
如何将其链接到我的 AppBundle 下的资源?如果有教程请给链接。提前致谢
Symfony2 从 App Bundle/Resources 下的视图开始,Symfony 3 尝试鼓励您将前端 (html/js/css) 与业务 php Bundle 分开,方法是将它们放在app/Resources
.
无论如何,如果您想按照您所描述的方式构建代码(如 symfony2 标准),则要使用的语法是bundle:folder:subdirs/views.html.twig
AppBundle // first parameter
-Controller
-Entity
-Form
-Resources
-views
-default //second parameter
- index.html.twig
- subfolder
- _included.html.twig
- subsubfolder
- _very_included.html.twig
在这个例子中:
-
index.html.twig
语法将是AppBundle:default:index.html.twig
-
_included.html.twig
语法将是AppBundle:default:subfolder/_included.html.twig
-
_very_included.html.twig
语法将是AppBundle:default:subfolder/subsubfolder/_very_included.html.twig
对于您的具体问题,它将是AppBundle:default:index.html.twig
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)