我试图覆盖一个文件 (index.html.twig) 中的 {% block %},该文件扩展了使用块的文件 (base.html.twig)。但是扩展文件包含另一个 twig 文件 (feature.twig),其中放置了覆盖 index.html.twig 内容的块。这有可能吗?也许除了包含声明之外还有别的东西?
{# index.html.twig #}
{% extends 'base.html.twig' %}
{{ include('feature.html.twig') }}
{# base.html.twig #}
{% block extraJs %}{% endblock %}
{# feature.html.twig #}
{% block extraJs %}<script>$('...');</script>{% endblock %}
Run Code Online (Sandbox Code Playgroud) 我将 Symfony 4 与预配置的“App”-Bundle(名称中没有“Bundle”)一起使用,并添加了如下扩展名。访问路由时,不会输出扩展的调试输出,因此扩展逻辑未运行。为什么?我没有在任何地方注册扩展,只是按照http://symfony.com/doc/current/bundles/extension.html 上的手册进行操作。
<?php
namespace App\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
class AppExtension extends Extension
{
public function __construct()
{
echo "EXTLOAD000|";
}
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
echo "EXTLOAD|";
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('app_transformer_configuration', $config['transformer_configuration']);
}
}
Run Code Online (Sandbox Code Playgroud)
除调试外的代码来自此站点:https : //blog.bam.tech/developper-news/make-a-versioned-api-with-symfony (Symfony 2.7)
我无法从数据库中获取数据.这是代码:
$testRepository= $this->getDoctrine()->getRepository('testBundle:test');
$potds = $testRepository->findBy(
array(),
);
Run Code Online (Sandbox Code Playgroud)
这是实体类:
* @ORM\Table()
* @ORM\Entity(repositoryClass="testBundle\Entity\test")
* @ORM\HasLifecycleCallbacks
*/
class test
{ /* ... */ }
Run Code Online (Sandbox Code Playgroud)
这是存储库的代码:
namespace testBundle\Entity;
/**
* TestRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class testRepository extends \Doctrine\ORM\EntityRepository
{
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误消息:symfony 2 - 尝试调用类"testBundle\Entity\test"的名为"findBy"的未定义方法
使用Doctrine插入数据是有效的,因此实体应该有一切正确.