小编Bil*_*ard的帖子

如何为 cli 参数(而非标志)指定“用法”

对于标志,我可以指定 --help 命令中出现的描述

flag.String("a", "", "Is is a flag")
Run Code Online (Sandbox Code Playgroud)

但我没有标志,只有参数,我像这样使用 cli

mycommand start 4
Run Code Online (Sandbox Code Playgroud)

是否可以使用 --help 查看“start”(和其他)参数的描述?

command-line-interface go

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

我如何在 Symfony 的订阅者中获取 entityManager

我使用 Api 平台。我有订阅者

namespace App\EventSubscriber\Api;

use ApiPlatform\Core\EventListener\EventPriorities;
use App\Entity\Product;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpKernel\KernelEvents;

final class ProductCreateSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return [
            KernelEvents::VIEW => ['createHost', EventPriorities::POST_WRITE],
        ];
    }

    public function createHost(GetResponseForControllerResultEvent $event)
    {
        $product = $event->getControllerResult();
        $method = $event->getRequest()->getMethod();

        if (!$product instanceof Product || Request::METHOD_POST !== $method) {
            return;
        }

        I NEED ENTITY MANAGER HERE
    }
}
Run Code Online (Sandbox Code Playgroud)

是否可以在这里找到实体经理?

创建产品后,我需要创建另一个实体

php symfony api-platform.com

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