Php 如何在AppBundle中添加视图?
我正试着在symfony3中进行实验。我试图在谷歌上搜索它,但我没有从他们那里找到明确的答案。这是symfony中的默认控制器Php 如何在AppBundle中添加视图?,php,symfony,Php,Symfony,我正试着在symfony3中进行实验。我试图在谷歌上搜索它,但我没有从他们那里找到明确的答案。这是symfony中的默认控制器 class DefaultController extends Controller { /** * @Route("/", name="homepage") */ public function indexAction(Request $request) { // replace this example c
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,
]);
}
}
如果看到返回渲染。它将显示来自app/Resources/views/default/index.html.twig的default/index.html.twig我想知道这是否可以将我的视图文件夹放入我的AppBundle文件夹?这是我在AppBundle中的列表文件夹
AppBundle
-Controller
-Entity
-Form
-Resources
-views
-default
-index.html.twig
如何将其链接到AppBundle下的资源?如果你有教程,请给链接。提前感谢Symfony2从AppBundle/Resources下的视图开始,而Symfony3试图通过将前端(html/js/css)放在
app/Resources
中来鼓励您将其从业务php包中分离出来
无论如何,如果您想按照描述的方式构造代码(如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
语法将是\u included.html.twig
AppBundle:default:subfolder/\u included.html.twig
语法将是\u very\u included.html.twig
AppBundle:default:subfolder/subsubfolder/\u very\u included.html.twig
对于您的具体问题,它将是
AppBundle:default:index.html.twig
您发布的内容看起来应该可以工作。尝试清除缓存并确保已删除应用程序/资源文件。“Symfony3尝试鼓励您将前端(html/js/css)从业务php包中分离出来”。如果是这样的话,那么为什么assetic从@AppBundle加载资产呢?它鼓励你,而不是强迫你这么做。Symfony 3的最佳实践是将它们放在app/Resources中,而不是src/Appbundle/Resources中。如果您有多个子文件夹呢?如果文件位于。/views/default/sub1/sub2/sub3/tmpl.html.twig
中,它是AppBundle:default:sub1:sub2:sub3/tmpl.html.twig
还是AppBundle:default:sub1/sub2/sub3/tmpl.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