I\'m new in symfony2.I created a repository class when I created an entity class through command line.But I couldn\'t access my custom functions in that repository class. ho
The manual has a nice step by step guide ... http://symfony.com/doc/current/book/doctrine.html#custom-repository-classes
I think you just forgot to register this repository in your entity. You just have to add in your entity configuration file the repository class.
In src/Mypro/symBundle/Resources/config/doctrine/Register.orm.yml:
Mypro\symBundle\Entity\Register:
type: entity
repositoryClass: Mypro\symBundle\Entity\RegisterRepository
Don't forget to clear your cache after this change, just in case.
And if you're using Annotations (instead of yml config) then instead of the above, add something like:
/**
* @ORM\Entity(repositoryClass="Mypro\symBundle\Entity\RegisterRepository")
*/
to your Entity class to register the repository
I simply follow to native documentation doc and look for the annotation that I selected. For example I selected yaml, added configurations to Product.orm.yml and Category.orm.yml files, also add new php attributes to Entity Methods :
protected $products;
public function __construct()
{
$this->products = new ArrayCollection();
}
for Category.php and
protected $category;
for Product.php
then run php app/console doctrine:generate:entities Acme
,that successfully add new getters and setters
xml for mapping: Update xml mapping file in folder Resource/config/doctrine, add repository-class attribute:
<entity name="Ccd\Bundle\FrontendBundle\Entity\UvUpdatePageContent" table="uv_update_page_content" repository-class="Ccd\Bundle\FrontendBundle\Entity\UvUpdatePageContentRepository">
http://doctrine-mongodb-odm.readthedocs.org/en/latest/cookbook/mapping-classes-to-orm-and-odm.html Then update cache:
php app/console doctrine:cache:clear-metadata
php app/console cache:clear
First of all You don't need custom repo to do that.. You can set the order by clause in the EM getRepository findBy method:
//$em - entity manager
//from Doctrine documentation: findBy(criteria(array), order(array), limit, offset)
$result = $em->getRepository('symBundle:Register')->findBy(array(), array('name' => 'ASC'))
I too lost a lot of time when I got into this mess of configuration. I was configuring the repository class in my Entity as annotation mapping. The mapping was there but still the repository was not associated with the entity. When I moved the annotation mapping i.e. @ORM\Entity(repositoryClass="Acme\DemoBundle\Entity\UserRepository"), to the last line, it worked.
/*
* User
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="Acme\DemoBundle\Entity\UserRepository")
*/
class User
{
...
}`