我剛開始了我的第一個symfony項目,並且在更復雜的情況下出現了上述錯誤。爲了縮小範圍,我創建一個新的項目,但錯誤的是有一次:/未知實體名稱空間別名'Appbundle'
我有什麼下來:
CD的/ var/WWW
須藤symfony的新EM
CD EM
須藤的mkdir的src /的appbundle /實體
須藤觸摸的src /的appbundle /實體/ Company.php
須藤搭配chmod -R 777 *
PHP斌/控制檯學說:數據庫://創建數據庫的symfony
PHP斌/控制檯學說:生成:實體的appbundle
須藤觸摸的src /的appbundle /Controller/CompanyController.php
須藤搭配chmod -R 777 * //無法寫入緩存
導航到http://em.at/app_dev.php/companies時出現錯誤!
我已經嘗試過Uncaught PHP Exception Doctrine\ORM\ORMException: "Unknown Entity namespace alias 'AppBundle'."
所以
PHP斌/控制檯高速緩存:明確
這就造成了
[Symfony的\分量\文件系統\異常\ IOException]
Faile d刪除文件「/ var/www/em/var/cache/de〜/ twig/2b/2bef18b12bca6cd9cb
d50ce5b194c23fdc85bb73d29114f27fb3793b7f085d8a.php」:。
所以我手動刪除它們
須藤RM -R緩存/日〜
須藤RM-R高速緩存的/ dev
但錯誤依然存在。任何人都知道什麼是錯的?
我的文件:
<?php
// src/AppBundle/Entity/Company.php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="company")
*/
class Company
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=100)
*/
private $name;
}
和
<?php
// src/AppBundle/Entity/CompanyController.php
namespace AppBundle\Controller;
use AppBundle\Entity\Company;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class CompanyController extends Controller
{
/**
* @Route("/companies", name="company_list")
*/
public function listAction(Request $request)
{
$companies = $this->getDoctrine()->getRepository('Appbundle:Company')->findAll();
// replace this example code with whatever you need
return $this->render('company/list.html.twig', [
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
'companies' => $companies
]);
}
}
''Appbundle:Company''應該是''AppBundle:Company'' at'$ companies = $ this-> getDoctrine() - > getRepository(...' – Yoshi
哦......男人......非常感謝: )這樣一個愚蠢的錯誤... –