我有问题2天了,我是Symfony的新手。
我正在使用Symfony 3.4。
我使用Sonata创建了一个后端来管理实体和用户。 我的后端还可以,但是现在树枝模板不再起作用。我只有空白页。 你能帮助我吗 ?预先谢谢你。
这是我的文件:
composer.json
{
"name": "renicom.com/rcmanager1",
"license": "proprietary",
"type": "project",
"autoload": {
"psr-4": {
"AppBundle\\": "src/AppBundle",
"Application\\": "src/Application"
},
"classmap": [
"app/AppKernel.php",
"app/AppCache.php"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
},
"files": [
"vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php"
]
},
"require": {
"php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/doctrine-migrations-bundle": "^1.3",
"doctrine/orm": "^2.5",
"friendsofsymfony/rest-bundle": "^2.3",
"incenteev/composer-parameter-handler": "^2.0",
"knplabs/knp-markdown-bundle": "^1.7",
"knplabs/knp-paginator-bundle": "^2.8",
"nelmio/api-doc-bundle": "^3.2",
"sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^5.0.0",
"sonata-project/admin-bundle": "^3.35",
"sonata-project/block-bundle": "^3.12",
"sonata-project/doctrine-orm-admin-bundle": "^3.6",
"sonata-project/easy-extends-bundle": "^2.5",
"sonata-project/google-authenticator": "^2.1",
"sonata-project/intl-bundle": "^2.5",
"sonata-project/media-bundle": "^3.13",
"sonata-project/user-bundle": "^4.2",
"symfony/monolog-bundle": "^3.1.0",
"symfony/polyfill-apcu": "^1.0",
"symfony/swiftmailer-bundle": "^2.6.4",
"symfony/symfony": "3.4.*",
"symfony/templating": "^4.1",
"twig/twig": "^1.0||^2.0"
},
"require-dev": {
"sensio/generator-bundle": "^3.0",
"symfony/phpunit-bridge": "^3.0"
},
"scripts": {
"symfony-scripts": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
],
"post-install-cmd": [
"@symfony-scripts"
],
"post-update-cmd": [
"@symfony-scripts"
]
},
"config": {
"sort-packages": true
},
"extra": {
"symfony-app-dir": "app",
"symfony-bin-dir": "bin",
"symfony-var-dir": "var",
"symfony-web-dir": "web",
"symfony-tests-dir": "tests",
"symfony-assets-install": "relative",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
},
"branch-alias": null
}
}
AppKernel.php
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
new Sonata\CoreBundle\SonataCoreBundle(),
new Sonata\BlockBundle\SonataBlockBundle(),
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
new Sonata\AdminBundle\SonataAdminBundle(),
new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle(),
new FOS\UserBundle\FOSUserBundle(),
new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
new Sonata\MediaBundle\SonataMediaBundle(),
new Application\Sonata\MediaBundle\ApplicationSonataMediaBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new Sonata\IntlBundle\SonataIntlBundle(),
new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle(),
new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
];
控制器
<?php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class AssetController extends Controller
{
/**
* @Route("/objets", name="asset_list_fr")
*/
public function listAction(Request $request, $slug = 'test'){
$asset_list = array();
if ($request->isMethod('GET')){
$params = $request->query;
$category = $this->getDoctrine()
->getRepository('AppBundle:Category');
$categoryP = $category->findOneBy(array('id' => 4));
$type = $this->getDoctrine()
->getRepository('AppBundle:Type');
$typeP = $type->findOneBy(array('id' => 30));
$sector = $this->getDoctrine()
->getRepository('AppBundle:Sector');
$sectorP = null;//$sector->findOneBy(array('id' => '3'));
$em = $this->getDoctrine()->getManager();
$asset_list = $em->getRepository('AppBundle:Asset')
->findBy(['category' => $categoryP]);
$assets = $this->get('knp_paginator')->paginate(
$asset_list, 1
);
}
return $this->render('asset/list.html.twig',
[
'slug' => $slug,
'assets' => $assets,
]);
}
}
我的观点asset / list.html.twig
{% extends 'base.html.twig' %}
{% block content %}
test
{% endblock %}
我的config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
parameters:
locale: en
framework:
translator: { fallbacks: ['%locale%'] }
secret: '%secret%'
router:
resource: '%kernel.project_dir%/app/config/routing.yml'
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
default_locale: '%locale%'
trusted_hosts: ~
session:
handler_id: session.handler.native_file
save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'
fragments: ~
http_method_override: true
assets: ~
php_errors:
log: true
twig:
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
doctrine:
dbal:
driver: pdo_mysql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: UTF8
types:
json: Sonata\Doctrine\Types\JsonType
orm:
auto_generate_proxy_classes: '%kernel.debug%'
entity_managers:
default:
auto_mapping: true
mappings:
ApplicationSonataUserBundle: ~
SonataUserBundle: ~
FOSUserBundle: ~
ApplicationSonataMediaBundle: ~
SonataMediaBundle: ~
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }
fos_user:
db_driver: orm # can be orm or odm
firewall_name: main
user_class: Application\Sonata\UserBundle\Entity\User
group:
group_class: Application\Sonata\UserBundle\Entity\Group
group_manager: sonata.user.orm.group_manager
service:
mailer: fos_user.mailer.twig_swift
user_manager: sonata.user.orm.user_manager
from_email:
address: "test1@test.com" #"%mailer_user%"
sender_name: "test1@test.com" #"%mailer_user%"
sonata_user:
security_acl: true
manager_type: orm
class:
user: Application\Sonata\UserBundle\Entity\User
group: Application\Sonata\UserBundle\Entity\Group
admin:
user:
class: Sonata\UserBundle\Admin\Entity\UserAdmin
controller: SonataAdminBundle:CRUD
translation: SonataUserBundle
group:
class: Sonata\UserBundle\Admin\Entity\GroupAdmin
controller: SonataAdminBundle:CRUD
translation: SonataUserBundle
sonata_block:
default_contexts: [cms]
blocks:
sonata.user.block.account:
sonata.admin.block.admin_list:
contexts: [admin]
sonata_admin:
title_logo : /images/logo_remicom.png
title: Remicom Admin
sonata_media:
db_driver: doctrine_orm
default_context: default
contexts:
default:
providers:
- sonata.media.provider.dailymotion
- sonata.media.provider.youtube
- sonata.media.provider.image
- sonata.media.provider.file
- sonata.media.provider.vimeo
formats:
small: { width: 100, quality: 70}
big: { width: 500, quality: 70}
cdn:
server:
path: /uploads/media
filesystem:
local:
directory: "%kernel.root_dir%/../public/uploads/media"
create: false
providers:
image:
resizer: sonata.media.resizer.square
sonata_intl:
timezone:
default: Europe/Paris
knp_paginator:
page_range: 30
我的routing.yml
app:
resource: '@AppBundle/Controller/'
type: annotation
admin_area:
resource: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
prefix: /admin
_sonata_admin:
resource: .
type: sonata_admin
prefix: /admin
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
sonata_user_admin_security:
resource: '@SonataUserBundle/Resources/config/routing/admin_security.xml'
prefix: /admin
sonata_user_admin_resetting:
resource: '@SonataUserBundle/Resources/config/routing/admin_resetting.xml'
prefix: /admin/resetting
我在此处从调试部分添加2屏幕。 The twig debug
答案 0 :(得分:0)
最后我解决了这个问题。我开始一个新项目,并以相同的方式重建我的Symfony应用程序的每个部分,并且一切正常。 我不知道是什么问题。我当然忘记了一点,但我不能说什么。