When outputting the code, an error occurs:
Attempted to call the "Doctrine \ Bundle \ DoctrineBundle \ Registry" called "persist" of class.
Rummaged could not find a solution. Here is my code:
protected function execute(InputInterface $input, OutputInterface $output) { $client = new Client(); // Go to the booking.com website $crawler = $client->request('GET', 'http://www.booking.com/country.en-gb.html'); $crawler = $crawler->filter('body#b2countryPage > div#bodyconstraint > div#bodyconstraint-inner > div.lp_flexible_layout_content_wrapper > div#countryTmpl > div.block_third > div.block_header'); foreach ($crawler as $domElement) { $countries = new Countries(); $countries->setCountry($domElement->getElementsByTagName('h2')->item(0)->textContent); $countries->setHotels($domElement->getElementsByTagName('span')->item(0)->textContent); $em = $this->getContainer()->get('doctrine'); $em->persist($countries); $em->flush(); } }