Ala vhebil Ala vhebil - 1 year ago 325
PHP Question

Symfony 2 Attempted to load class " " from namespace " " Did you forget a "use" statement for another namespace?

I am trying to use the Entity Philip inside a Symfony Controller

But this error Showing whene i want to load the route

Erro Screenshot


Attempted to load class “PhilipRepositroy ” from namespace
“AppBundle\Repository ” Did you forget a “use” statement for another
namespace?


This is My Controller

/**
* @Route("/see", name="see")
*/
public function SeeAction()
{
// replace this example code with whatever you need

$Philip = $this->getDoctrine()
->getRepository('AppBundle:Philip')
->findAll();

return $this->render('business/see.html.twig', array(
'Philip' => $Philip
));

}


My Entity Called : Philip.php

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* Philip
*/
class Philip
{
/**
* @var int
*/
private $id;

/**
* @var string
*/
private $philipname;

/**
* @var string
*/
private $philipemail;

/**
* @var string
*/
private $philipphone;

/**
* @var string
*/
private $philipregion;

/**
* @var string
*/
private $philipville;

/**
* @var string
*/
private $philipcin;

/**
* @var string
*/
private $philipcv;

/**
* @var string
*/
private $philipgender;


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

/**
* Set philipname
*
* @param string $philipname
* @return Philip
*/
public function setPhilipname($philipname)
{
$this->philipname = $philipname;

return $this;
}

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

/**
* Set philipemail
*
* @param string $philipemail
* @return Philip
*/
public function setPhilipemail($philipemail)
{
$this->philipemail = $philipemail;

return $this;
}

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

/**
* Set philipphone
*
* @param string $philipphone
* @return Philip
*/
public function setPhilipphone($philipphone)
{
$this->philipphone = $philipphone;

return $this;
}

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

/**
* Set philipregion
*
* @param string $philipregion
* @return Philip
*/
public function setPhilipregion($philipregion)
{
$this->philipregion = $philipregion;

return $this;
}

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

/**
* Set philipville
*
* @param string $philipville
* @return Philip
*/
public function setPhilipville($philipville)
{
$this->philipville = $philipville;

return $this;
}

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

/**
* Set philipcin
*
* @param string $philipcin
* @return Philip
*/
public function setPhilipcin($philipcin)
{
$this->philipcin = $philipcin;

return $this;
}

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

/**
* Set philipcv
*
* @param string $philipcv
* @return Philip
*/
public function setPhilipcv($philipcv)
{
$this->philipcv = $philipcv;

return $this;
}

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

/**
* Set philipgender
*
* @param string $philipgender
* @return Philip
*/
public function setPhilipgender($philipgender)
{
$this->philipgender = $philipgender;

return $this;
}

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


** My Repository file AppBundle\Repository\PhilipRepository**

<?php

namespace AppBundle\Repository;

use Doctrine\ORM\EntityRepository;

/**
* PhilipRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class PhilipRepository extends EntityRepository
{
}


what i can do to resolve this problem ! i m new in Symfony

Answer Source

So I guess you failed to get Repository class? Then in your Philip entity class add mappings

   use Doctrine\ORM\Mapping as ORM;

   /**
    * @ORM\Entity(repositoryClass="AppBundle\Repository\PhilipRepository")
    */
    class Philip
    {
       ...
    }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download