1

I want to run php script in command line. I have created this file into root folder. and want to run only once.

binary.php

global $em;
$binaryContentRepository = $em->getRepository('\xxx\Entity\xxxx');
$datas = $binaryContentRepository->getAllAttechment();
foreach($datas as $data){
    $ext =  pathinfo($data['filename'], PATHINFO_EXTENSION);
    file_put_contents("C:\\xxxxxx\\".$data['id'].".".$ext, $data['content']);
}

I have try to run this file php -f binary.php. But can not run successfully.

3
  • do you get any errors? Commented Mar 24, 2021 at 0:25
  • 1
    Yes. Fatal error: Call to a member function getRepository() on null Commented Mar 24, 2021 at 0:57
  • 1
    where is $em; set? Commented Mar 24, 2021 at 2:17

1 Answer 1

2

To run Symfony is the command line you need to create a Symfony command.

Note: just like a controller in a command you must have your dependency injection setup if you want to communicate to a database with entity manager.

https://symfony.com/doc/current/console.html

Then you would execute from the Symfony project root:

php bin/console your_command_name

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.