1
votes

I have just started my first symfony project and I'm getting the above error in a more complex situation. To narrow it down I created a new project but the error is there again :/

What I have down:

cd /var/www

sudo symfony new em

cd em

sudo mkdir src/AppBundle/Entity

sudo touch src/AppBundle/Entity/Company.php

sudo chmod -R 777 *

php bin/console doctrine:database:create // db symfony

php bin/console doctrine:generate:entities AppBundle

sudo touch src/AppBundle/Controller/CompanyController.php

sudo chmod -R 777 * // failed to write to cache

When navigating to http://em.at/app_dev.php/companies I get the error!

I already tried Uncaught PHP Exception Doctrine\ORM\ORMException: "Unknown Entity namespace alias 'AppBundle'."

so

php bin/console cache:clear

which resulted in

[Symfony\Component\Filesystem\Exception\IOException]
Failed to remove file "/var/www/em/var/cache/de~/twig/2b/2bef18b12bca6cd9cb
d50ce5b194c23fdc85bb73d29114f27fb3793b7f085d8a.php": .

so I deleted them manually

sudo rm -R cache/de~

sudo rm -R cache/dev

but the error persists. Anyone know what's wrong?.

my files:

<?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;

}

and

<?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
        ]);
    }

}
1
'Appbundle:Company' should be 'AppBundle:Company' at $companies = $this->getDoctrine()->getRepository(...Yoshi
oh man... thank you very much :) such a stupid mistake...Brucie Alpha

1 Answers

0
votes

Did you set the file permissions on your var folder. Form the above messages it looks like you may not have done that. Here's the reference you need:

https://symfony.com/doc/current/setup/file_permissions.html

Also, just in case run:

php bin/symfony_requirements

to make sure you've met all other requirements. This will save you a lot of grief.