标签: symfony4

如何配置Doctrine以在Symfony 4上使用yaml映射

我是Symfony 4的新手

我使用Doctrine,我想使用yaml实体映射.所以我配置了文件doctrine.yaml并更改type:annotationtype:yml.

当我尝试时php bin/console make:entity,没有生成链接到该实体的yaml映射文件

这是我的doctrine.yaml档案:

parameters:
    # Adds a fallback DATABASE_URL if the env var is not set.
    # This allows you to run cache:warmup even if your
    # environment variables are not available yet.
    # You should not need to change this value.
    env(DATABASE_URL): ''

doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4

        # With Symfony 3.3, …

mapping yaml symfony doctrine-orm symfony4

6
推荐指数
1
解决办法
6189
查看次数

Symfony 4在DI Extension类中加载和处理自定义Yaml配置文件

我正在尝试按照此处提供的文档在我的应用程序中导入yaml配置文件:http://symfony.com/doc/current/bundles/extension.html但我总是有错误消息:没有扩展能够加载"app"的配置

我的文件位于:config/packages/app.yaml,具有以下结构:

app:  
    list:  
        model1:  
            prop1: value1
            prop2: value2  
        model2:
            ...
Run Code Online (Sandbox Code Playgroud)

由于这是一个简单的应用程序,所有文件都在"src /"中.所以我有:
src/DependencyInjection/AppExtension.php

<?php

namespace App\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

class AppExtension extends Extension
{
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);
    }
}
Run Code Online (Sandbox Code Playgroud)

SRC/DependencyInjection /的configuration.php

<?php

namespace App\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('app');

        // …
Run Code Online (Sandbox Code Playgroud)

yaml symfony symfony4

6
推荐指数
1
解决办法
4670
查看次数

Symfony 4 SwiftMailer Gmail:未发送电子邮件

我目前正在研究Symfony 4应用程序,我需要通过Swift Mailer发送电子邮件.当我发送电子邮件时,我收到假脱机电子邮件,但我没有收到我的Gmail邮箱.我允许在我的Gmail配置中使用不安全的应用程序.

这是来自.env文件的邮件程序URL:MAILER_URL = gmail://ep****@gmail.com:PASSWORD @ localhost

这是我的swiftmailer.yaml:

    #config/packages/swiftmailer.yaml
    swiftmailer:
        url: '%env(MAILER_URL)%'
        spool: { type: 'memory' }
Run Code Online (Sandbox Code Playgroud)

这是我的控制器功能:

SRC /控制器/ AccountController.php

完成表格后

这是我遵循的文档:http: //symfony.com/doc/current/email.html

我已经检查了这些问题,但他们没有给我答案:如何从运行在Windows 10上的本地计算机上发送带有Symfony 4 Swiftmailer的电子邮件?,邮件symfony 4无法正常工作

拜托,我需要帮助.我整天都在寻找解决方案.我没有错,但我没有收到邮件.提前致谢.任何链接都可以帮助我.

php gmail swiftmailer symfony4

6
推荐指数
1
解决办法
1万
查看次数

注释在Symfony 4中不起作用

我尝试使用Symfony 4开发,所以我按照symfony.com上的教程进行操作

我尝试访问时遇到错误:

http://localhost:8000/
Run Code Online (Sandbox Code Playgroud)

这是错误:

[语法错误]预期的PlainValue,在/ Users/*****/Documents/ProjetSymfo4/my-project/config/routes /中的方法App\Controller\HomeController :: home()中的位置7得到''' /../src/Controller/(从"/Users/*****/Documents/ProjetSymfo4/my-project/config/routes/annotations.yaml"导入).确保已安装并启用注释.

我已经跑了

作曲家需要注释

它已安装

In composer.json : 

"require": {
    "php": "^7.1.3",
    "ext-iconv": "*",
    "sensio/framework-extra-bundle": "^5.1",
Run Code Online (Sandbox Code Playgroud)

这是我的项目:

在此输入图像描述

谢谢您的帮助

php annotations symfony symfony4

6
推荐指数
1
解决办法
5367
查看次数

部署Symfony应用-ClassNotFoundException错误

我正在学习Symfony框架,并尝试使用Git将我放在一起的简单样板应用程序部署到Heroku。

由于以下致命错误,导致部署失败:

Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "WebServerBundle" from namespace "Symfony\Bundle\WebServerBundle

Did you forget a "use" statement for another namespace? in /tmp/build_cbeb92af6c9ee04b07e1f85618211649/src/Kernel.php:32

内核.php

<?php

namespace App;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;

class Kernel extends BaseKernel {

    use MicroKernelTrait;

    const CONFIG_EXTS = '.{php,xml,yaml,yml}';

    public function getCacheDir(){

        return $this->getProjectDir().'/var/cache/'.$this->environment;
    }

    public function getLogDir(){

        return $this->getProjectDir().'/var/log';
    }

    public function registerBundles(){

        $contents = require $this->getProjectDir().'/config/bundles.php';
        foreach ($contents as $class => $envs) {
            if (isset($envs['all']) || isset($envs[$this->environment])) …
Run Code Online (Sandbox Code Playgroud)

php deployment heroku symfony symfony4

6
推荐指数
1
解决办法
3134
查看次数

Symfony 4 - 在连接时删除自己的用户帐户的良好做法

我希望我的用户能够删除他们自己的用户帐户。我做了一个SecurityController有我的 3 个函数的地方loginlogoutdeleteUser. 当我删除数据库中的当前用户时,会出现此错误:

您不能从不包含标识符的 EntityUserProvider 刷新用户。用户对象必须使用由 Doctrine 映射的自己的标识符进行序列化。

当我删除另一个用户时,它可以正常工作,因为他没有连接。我是否必须序列化用户并通过服务传递它,注销用户然后在服务中将其删除?或者我可以清除控制器中的 PHP 会话,但我不知道如何使用我认为它自版本 4 以来发生了变化。

<?php

namespace App\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;

use App\Entity\User;
use App\Form\UserType;

class SecurityController extends Controller
{
  /**
   * @Route("/createAdmin", name="create_admin")
   */
    public function createAdminUser(Request $request, UserPasswordEncoderInterface $passwordEncoder)
    {
      $usersRepo = $this->getDoctrine()->getRepository(User::class);
      $uCount = $usersRepo->countAllUsers();

      if ($uCount == 0)
      {
        $user = new User();
        $form = $this->createForm(UserType::class, …
Run Code Online (Sandbox Code Playgroud)

session logout symfony symfony4

6
推荐指数
1
解决办法
5137
查看次数

如何将实际的 ENV var 值加载到我的包配置中?

我正在尝试制作一个 Symfony 包。但是我无法读取我在配置中使用的 ENV 变量。(它们仅作为占位符加载)我创建了一个配置树,其中包含一些我希望应用程序与 ENV 变量一起使用的值。

应用程序配置文件如下所示:

bundle_name:
    config_value: "%env(NAME_OF_ENV_VALUE)%"
Run Code Online (Sandbox Code Playgroud)

我的 Bundle 扩展类看起来像:

public function load(array $configs, ContainerBuilder $container): void
{
    $loader = new XmlFileLoader(
        $container,
        new FileLocator(__DIR__.'/../Resources/config')
    );

    $configuration = new Configuration();
    $loader->load('services.xml');
    $config = $this->processConfiguration($configuration, $configs);

    print_r($config);
}
Run Code Online (Sandbox Code Playgroud)

结果print_r($config)如下:

 [config_value] => env_NAME_OF_ENV_VALUE_2ae7ade5b0635007828f2e7e6765cd4d
Run Code Online (Sandbox Code Playgroud)

另外,我收到此异常:

环境参数异常

从不使用环境变量“ENV_VAR_NAME”。请检查您的容器的配置。在 PhpDumper.php 中(第 271 行)

现在,我的问题是

我如何(结果是ENV 占位符)转换为 ENV 变量的实际值?

我尝试过的一些事情

我知道有一个ContainerBuilder->compile(true)选项可以解决这些 ENV 变量。但我不知道我应该把它放在我的包里的什么地方。我试过的一切都会出错。

我也知道有一个 CompilerPass (Symfony\Component\DependencyInjection\Compiler\ResolveEnvPlaceholdersPass) 它(根据名称)应该解析环境变量,但这没有做任何事情。我尝试添加$container->addCompilerPass(new ResolveEnvPlaceholdersPass());到我的 Bundle 类的 build() 方法,但没有任何反应。

一些附加信息

  • 我正在使用 …

php environment-variables symfony symfony4

6
推荐指数
1
解决办法
2199
查看次数

从symfony 3.4迁移到symfony 4

我的项目目前已安装3.4版本的symfony。我想转到symfony4。因此,根据http://symfony.com/doc/current/setup/upgrade_major.html中的建议,我转到了symfony4 。

在我当前的项目中,在src目录中创建了许多自定义包。但是现在在Symfony 4中没有捆绑结构。

因此,请指导我如何继续使用Symfony4中现有的捆绑软件?

提前致谢...

php migration symfony symfony-3.4 symfony4

6
推荐指数
1
解决办法
3530
查看次数

如何在symfony 4中启用分析器

解决了:

我重新安装它,现在它包含web_profiler.yalm.谢谢大家.


最初的问题是:

我刚刚开始学习Symfony所以我在KnpUniversity下载了免费视频以开始学习.当我到达视频"Web调试工具栏和Profiler!"时 我完成了下一个命令:

> composer require profiler --dev
Run Code Online (Sandbox Code Playgroud)

它安装好了.

然后,当我在浏览器中打开我的应用程序时,"(...)底部光滑的黑条......"没有显示出来.

我读到某处可能是因为我没有安装symfony/debug但是看看我的composer.json:

"require-dev": {
        "sensiolabs/security-checker": "^4.1",
        "symfony/debug": "^4.0",
        "symfony/dotenv": "^4.0",
        "symfony/profiler-pack": "^1.0",
        "symfony/web-server-bundle": "^4.0"
    },
Run Code Online (Sandbox Code Playgroud)

所以我安装了它.

我执行了以下命令,该命令在我的项目中为我提供了探查器配置:

> php bin/console debug:config web_profiler                   

Current configuration for extension with alias "web_profiler" 
============================================================= 

web_profiler:                                                 
    toolbar: false                                            
    intercept_redirects: false                                
    excluded_ajax_paths: '^/((index|app(_[\w]+)?)\.php/)?_wdt'
Run Code Online (Sandbox Code Playgroud)

如上所示,工具栏设置为false,如何激活它?或者如何让Profiler栏出现?

我正在使用:

  • Composer版本1.6.5,
  • Symfony 4.1.1和
  • PHP 7.2.7

提前致谢.

解:

我创建了一个新项目并且它有效,当作曲家下载包时似乎是一个错误.

php profiler symfony symfony4

6
推荐指数
1
解决办法
6217
查看次数

从 Symfony 日志记录中排除基于通道和级别的日志条目

我当前的配置:

monolog:
    handlers:
        target_main:
            type:         fingers_crossed
            action_level: debug
            handler: file_log
            channels: ['!security' '!request']
        file_log:
            type: rotating_file
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug
            max_files: 2
Run Code Online (Sandbox Code Playgroud)

现在请求通道已完全排除在 file_log 处理程序之外。我需要仅从通道请求中排除 action_level - 调试,而不是完全请求通道。是否可以使用 symfony monolog 配置,如果可以,如何实现?

php symfony monolog symfony4

6
推荐指数
0
解决办法
669
查看次数