Php 如何使控制器在Symfony 4中返回响应?
根据本教程,我在Symfony 4中安装了DataTableBundle: 为此:Php 如何使控制器在Symfony 4中返回响应?,php,symfony,return-value,Php,Symfony,Return Value,根据本教程,我在Symfony 4中安装了DataTableBundle: 为此: return $this->render('list.html.twig', ['datatable' => $table]); 但是我得到了一个空白页面,上面写着加载…,没有其他内容 list.html.twig: <!-- in the <head> section --> <link rel="stylesheet" type="text/css" href="h
return $this->render('list.html.twig', ['datatable' => $table]);
但是我得到了一个空白页面,上面写着加载…
,没有其他内容
list.html.twig:
<!-- in the <head> section -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-3.2.1/dt-1.10.16/datatables.min.css"/>
<!-- Insert this where you want the table to appear -->
<div id="presidents">Loading...</div>
<!-- before the closing <body> tag -->
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-3.2.1/dt-1.10.16/datatables.min.js"></script>
<!-- Insert this at the end of your body element, but before the closing tag -->
<script src="{{ asset('bundles/datatables/js/datatables.js') }}"></script>
<script>
$(function() {
$('#presidents').initDataTables({{ datatable_settings(datatable) }});
});
</script>
失踪的返回确实是问题所在。在你的list.html.twig中会找到一个空白页面上写有“Loading…”字样的原因。但是要解决这个问题,您必须提供更多的代码。您是否像这里提到的那样将config部分添加到config.yml中。因为地址表有一个默认模板,这将导致html代码注入到list.html中的占位符#presidents中。twig@KlausSchürg我将它添加到我的服务中。yaml但这不起作用,所以我删除了它。我想我没有config.yamli,如果我将其添加到services.yaml,则配置键“language_from_cdn”在“/Users/work/project/config/services.yaml”中的定义“datatables”不受支持。允许的配置键是/Users/work/project/config/services.yaml中的“别名”、“父级”、“类”、“共享”、“合成”、“惰性”、“公共”、“抽象”、“不推荐”、“工厂”、“文件”、“参数”、“属性”、“配置器”、“调用”、“标记”、“装饰”、“装饰内部名称”、“装饰优先级”、“自动连线”、“自动配置”、“绑定”(加载在resource/Users/work/project/config/services.yaml中)。在打开呈现html的源代码时,您是否安装了这些资产,它们是否可用?可能只是js没有加载?很高兴听到:-)祝您周末愉快。。。
return $this->render('list.html.twig', ['datatable' => $table]);
<!-- in the <head> section -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-3.2.1/dt-1.10.16/datatables.min.css"/>
<!-- Insert this where you want the table to appear -->
<div id="presidents">Loading...</div>
<!-- before the closing <body> tag -->
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-3.2.1/dt-1.10.16/datatables.min.js"></script>
<!-- Insert this at the end of your body element, but before the closing tag -->
<script src="{{ asset('bundles/datatables/js/datatables.js') }}"></script>
<script>
$(function() {
$('#presidents').initDataTables({{ datatable_settings(datatable) }});
});
</script>
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: 'en'
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
public: false # Allows optimizing the container by removing unused services; this also means
# fetching services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/*'
exclude: '../src/{Entity,Migrations,Tests,Kernel.php}'
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones