-1
請檢查我的代碼。學說類未找到
我有一個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;
和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;
}
}
並且此文件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";
運行通過終端文件 「創建product.php」 和我收到此錯誤:
HP Fatal error: Class 'Product' not found in /Applications/XAMPP/xamppfiles/htdocs/ClinicaDental/create_product.php on line 10
找不到類。
請幫我這個文件。 Regards
不是'new Products();'? (複數) – Farkie
你命名你的類產品:) – Pete
謝謝你們。新產品();是正確的 –