Я пытаюсь искать решения, чтобы создать команду для вставки в базу данных для данных динамически я не нашел какие-либо решения вы можете мне помочь сайтам
Я уже создать команду, консультации с официальной документацией Symfony но мой prblème как создать команду для обеспечения базы данных, которые используют DoctrineFixturesBundleСоздать команду с Symfony 2
<?php
namespace Test\FrontBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Helper\DialogHelper;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Form\FormBuilderInterface;
use Doctrine\Common\Annotations\AnnotationException;
class HelloCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('demo:alimentation')
->setDescription('Alimentation base de données ')
->setDefinition(array(
new InputOption('table', '', InputOption::VALUE_REQUIRED, 'Le nom de la table '),
new InputOption('entity', '', InputOption::VALUE_REQUIRED, 'entity concerned')
))
;
}
protected function interact(InputInterface $input, OutputInterface $output)
{
parent::interact($input, $output);
//$dialog = $this->getDialogHelper();
$helper = $this->getHelper('question');
$question = new ConfirmationQuestion('Continue with this action?', false);
if (!$helper->ask($input, $output, $question)) {
return;
}
$output->writeln(array(
'',
' Bienvenue ',
'',
'Cet outil va vous permettre de insérer dans la base de donnée dynamiquement ',
'',
));
$dialog = $this->getHelperSet()->get('dialog');
$entity = $dialog->ask($output, 'What is the name of the entity?');
$input->getOption('entity');
$table = $dialog->ask($output, 'What is the name of the table?');
$input->getOption('table');
$input->setOption('entity', $entity);
$input->setOption('table', $table);
}
protected function getDialogHelper()
{
$dialog = $this->getHelperSet()->get('dialog');
if (!$dialog || get_class($dialog) !== 'Sensio\Bundle\GeneratorBundle\Command\Helper\DialogHelper') {
$this->getHelperSet()->set($dialog = new DialogHelper());
}
return $dialog;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$dialog = $this->getDialogHelper();
if ($input->isInteractive()) {
$question = new ConfirmationQuestion('Do you confirm generation?', true);
if (!$dialog->askConfirmation($output, $question->getQuestion(), true)) {
$output->writeln('<error>Command aborted</error>');
return 1;
}
}
// On recupere les options
$entity = $input->getOption('entity').'()';
$table = $input->getOption('table');
$name = $input->getArgument('name');
$prenom = $input->getArgument('prenom');
public function createAction(Request $request)
{
$form = $this->createFormBuilder(new $entity)//un passage d'identité
->add('name', null, array('label' => 'Nom de l\'album '))
->add('type', null, array('label' => 'Type de l\'album'))
->add('artist', null, array('label' => 'Artist'))
->add('duration', null, array('label' => 'Duration de l\'album'))
->add('released', 'date', array('label' => 'Date de l\'album'))
->add('submit', 'submit')// les add pour la personalisation
->getForm();//pour récupérer le formulaire
//c'est la logique :il faut le déplacer
$form->handleRequest($request);
if ($request->isMethod('post') && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($form->getData());
$em->flush();
return $output->$this->render('TestFrontBundle:Sheet:create.html.twig', array('form' => $form->getForm()->createView()));
}
}
}
Вы должны разработать его, следуя документации Symfony, и если вы столкнулись с проблемой, разместите его здесь, добавив используемый код. –
Я уже создаю команду, консультируясь с официальной документацией Symfony , но моя prblème - это то, как создать команду для предоставления базы данных без использования DoctrineFixturesBundle – Khouloud
Возможно, обновите свой вопрос некоторым кодом. Чтобы вставить вас, просто вытащите диспетчера объектов из контейнера, новый ваш объект затем сохранит/сбросит, – Cerad