2016-10-26 37 views
-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

+2

不是'new Products();'? (複數) – Farkie

+1

你命名你的類產品:) – Pete

+1

謝謝你們。新產品();是正確的 –

回答

0

不是新產品(); ? (複數) - Farkie 10月26日18:52 你命名你的類產品:) - 皮特10月26日18:53 謝謝你們。新產品();是正確的 - ronal vasquez 10月26日19:00

@Farkie謝謝,類名在我的應用程序中是錯誤的。 - 羅納斯奎茲10月26日19:02
@佩特謝謝你,是你的解決方案。 - ronal vasquez 10月26日19:04

你用什麼瀏覽器?我建議檢查PHPStorm,它在過去幾年裏有了很大的改進。它有1個月的免費版本。 - TomášVotruba 10月26日19:13

瀏覽器?你的意思是IDE? - Farkie 10月26日19:36