小编Syl*_*llz的帖子

Symfony:显式定义服务中的容器

更新后我有这个弃用:

Since symfony/dependency-injection 5.1: The "Symfony\Component\DependencyInjection\ContainerInterface" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it. It is being referenced by the "App\Service\ImportService" service.
Run Code Online (Sandbox Code Playgroud)

这是我的ImportService

<?php

namespace App\Service;

use Symfony\Component\DependencyInjection\ContainerInterface;

class ImportService
{
    private $doctrine;
    private $em;

    public function __construct(ContainerInterface $container)
    {
        $this->doctrine = $container->get('doctrine'); //needed for database queries
        $this->em = $this->doctrine->getManager(); //needed for database queries
    }

    /** more methods here **/

}
Run Code Online (Sandbox Code Playgroud)

那么我究竟如何使它明确呢?我用谷歌搜索了一下,我认为我必须以services.yml某种方式将它添加到我的文件中。但我不确定如何+我必须为每个服务类做这件事?

dependency-injection symfony

2
推荐指数
1
解决办法
1941
查看次数

PHP 7 - 警告:array_column() 期望参数 1 是数组,给定的对象

我刚刚在我的项目中发现了一些奇怪的东西。我正在使用 PHP7.3 并且我正在尝试将该array_column()函数与对象一起使用。

我正在使用一个命令来调用一个 symfony 项目中的服务 - 如果这很重要,但是我已经将我的代码简化为最重要的。

文章.php :

class Article {
    private $id;
    private $category;

    public function __construct()
    {
        $this->category = new ArrayCollection();
    }

    public function getCategory(): Collection
    {
        return $this->category;
    }

    public function addCategory(ArticleCategory $category): self
    {
        if (!$this->category->contains($category)) {
            $this->category[] = $category;
        }

        return $this;
    }

    public function removeCategory(ArticleCategory $category): self
    {
        if ($this->category->contains($category)) {
            $this->category->removeElement($category);
        }

        return $this;
    }
}
Run Code Online (Sandbox Code Playgroud)

文章分类.php

class ArticleCategory
{
    private $id;
    private $name;

    public function getName(): ?string
    { …
Run Code Online (Sandbox Code Playgroud)

php command symfony php-7

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

标签 统计

symfony ×2

command ×1

dependency-injection ×1

php ×1

php-7 ×1