我有一个实体Product
.我的产品可以有多个不同语言的名称.法语名称,英语名称等.我不想使用自动翻译.
用户必须在"产品"表单中写入名称并选择相应的语言.由于添加按钮,他可以根据需要添加许多名称.
所有语言都是由admin用户创建的(另一种形式).因此,Language
也是一个具有名称(例如:英语)和代码(例如EN)的实体.
我创建了ProductName
具有名称和语言的Entity (符合用户在Product表单中写入的内容).
在这种情况下,我不需要将实体ProductName
与实体相关联Language
.我只想要语言代码.所以,在我的ProductName
实体中,我有这个属性:
/**
* @ORM\Column(name="Language_Code", type="string", length=2)
*/
private $language;
Run Code Online (Sandbox Code Playgroud)
我的产品表单(ProductType)有一个CollectionType字段,以便添加多个名称.
// Form/ProductType.php
->add('infos', CollectionType::class, array(
'entry_type' => ProductInfosType::class,
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'label' => false,
'mapped' => false
))
Run Code Online (Sandbox Code Playgroud)
ProductInfosType表单有2个字段:
// Form/ProductInfosType.php
->add('name', TextType::class, array(
'attr' => array('size' => 40)
))
->add('language', EntityType::class, array(
'placeholder' => '',
'class' => 'AppBundle:Language',
'choice_label' => 'code',
'attr' => array('class' => 'lang'), …
Run Code Online (Sandbox Code Playgroud) 我有一个包含超过690 000 行的 .csv 文件。
我找到了一个导入数据的解决方案,效果很好,但有点慢......(每 3 秒大约 100 条记录 = 63 小时!!)。
如何改进我的代码以使其更快?
我通过控制台命令进行导入。
另外,我想仅导入数据库中尚未存在的处方者(以节省时间)。让事情变得复杂的是,没有一个字段是真正唯一的(除了 id)。
两名处方者可以具有相同的姓氏、名字、居住在同一城市并且具有相同的 RPPS 和专业代码。但是,正是这 6 个领域的组合才使它们独一无二!
这就是为什么我在创建新字段之前检查每个字段的原因。
<?php
namespace AppBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Helper\ProgressBar;
use AppBundle\Entity\Prescriber;
class PrescribersImportCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
// the name of the command (the part after "bin/console")
->setName('import:prescribers')
->setDescription('Import prescribers from .csv file')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
// Show when the script is launched …
Run Code Online (Sandbox Code Playgroud) choice ×1
choicefield ×1
command-line ×1
csv ×1
entity ×1
mysql ×1
object ×1
symfony ×1
symfony-3.3 ×1