ronal vasquez ronal vasquez - 1 month ago 16
PHP Question

Doctrine Class not found

please check my code.

i have a composer.json

{
"require": {
"doctrine/orm": "2.4.*",
"symfony/yaml": "2.*"
},
"autoload": {
"psr-0": {"": "src/"}
}}


bootstrap.php

use Doctrine\ORM\Tools\Setup;
require_once "vendor/autoload.php";
$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode,null,null,false);
$conn = array(
'driver' => 'pdo_mysql',
'host' => '127.0.0.1',
'user' => 'root',
'password' => '',
'dbname' => 'ClinicaDental'
);
$entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);


cli-config.php

<?php
// cli-config.php
require_once "bootstrap.php";

$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($entityManager)
));

return $helperSet;


and Products.php

<?php



use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Table(name="products")
* @ORM\Entity
*/
class Products
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;

/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;



/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}

/**
* Set name
*
* @param string $name
* @return Products
*/
public function setName($name)
{
$this->name = $name;

return $this;
}

/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
}


and this file create_products.php

<?php
// create_product.php
require_once "bootstrap.php";
require_once './src/Products.php';



$newProductName = $argv[1];

$product = new Product();
$product->setName($newProductName);

$entityManager->persist($product);
$entityManager->flush();

echo "Created Product with ID " . $product->getId() . "\n";


run through the terminal file "create product.php" and I receive this error:

HP Fatal error: Class 'Product' not found in /Applications/XAMPP/xamppfiles/htdocs/ClinicaDental/create_product.php on line 10


Class Not Found.

Please help me with this file.
Regards

Answer

Wouldn't it be new Products(); ? (plural) – Farkie Oct 26 at 18:52 1
You named your class Products :) – Pete Oct 26 at 18:53 1
Thanks guys. new Products(); is correct – ronal vasquez Oct 26 at 19:00

@Farkie thanks, the class name is wrong in my application. – ronal vasquez Oct 26 at 19:02
1
@Pete thanks you, is correct your solution. – ronal vasquez Oct 26 at 19:04

What browser do you use? I'd recommend checking PHPStorm, it greatly improved in last few years. It has 1-month free version. – Tomáš Votruba Oct 26 at 19:13

Browser? You mean IDE? – Farkie Oct 26 at 19:36

Comments