I made sqlite database using doctrine 2. When i run create_product.php from console it works fine, but i want to create product from php class. So i made method with create_product.php code and included bootstrap.php, but i had issue: Undefined variable: entityManager.
create_product.php
<?php
// create_product.php
require_once "bootstrap.php";
$name = 'name';
$date = date("d.m.Y");
$time = time();
$product = new Product();
$product->setName($name);
$product->setSaveDate($date);
$product->setSaveTime($time);
$entityManager->persist($product);
$entityManager->flush();
echo "Created product with ID " . $response->getId() . "\n";
?>
and php class file:
<?php
namespace app\monitor;
use Product;
require_once dirname(dirname(dirname(__DIR__))) . "/bootstrap.php";
class Service {
$this->saveProduct('name');
public function saveProduct($name) {
$date = date("d.m.Y");
$time = time();
$entity = new Product();
$entity->setName($name);
$entity->setSaveTime($time);
$entity->setSaveDate($date);
$entityManager->persist($entity);
$entityManager->flush();
}
}
Why it's work from console, but doesn't work in method?
Aucun commentaire:
Enregistrer un commentaire