du512053619 2015-09-25 09:39
浏览 62

基于控制台命令参数的服务参数

I have situation where I have several entity managers like

  entity_manager_en
  entity_manager_us
  entity_manager_pl

etc.

Each entity manager refers to database with different language content.

I have command, where required argument is lang (language). I also have service which as constructor argument require entity manager.

Is it possible to somehow create dynamically entity manager based on lang given in command and pass it as my service argument while it is creating?

I tried with ConsoleCommandEvent but it fires before input contain arguments...

  • 写回答

1条回答 默认 最新

  • dongxingchang9345 2015-09-25 10:14
    关注

    If you want call entity manager in execute method in your command you can get argument and add it to getManager() method:

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $lang = $input->getArgument('lang');
    
        $em = $this->getContainer()->get('doctrine')->getManager('entity_manager_' . $lang);
    
        ...
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝