{"id":6527,"date":"2014-04-20T08:16:50","date_gmt":"2014-04-20T08:16:50","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/20\/custom-repository-class-in-symfony2-collection-of-common-programming-errors-2\/"},"modified":"2014-04-20T08:16:50","modified_gmt":"2014-04-20T08:16:50","slug":"custom-repository-class-in-symfony2-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/20\/custom-repository-class-in-symfony2-collection-of-common-programming-errors-2\/","title":{"rendered":"custom repository class in symfony2-Collection of common programming errors"},"content":{"rendered":"<p>Hi stackoverflow friends,<\/p>\n<p>I&#8217;m new in symfony2.I created a repository class when I created an entity class through command line.But I couldn&#8217;t access my custom functions in that repository class. how to create custom repository class in symfony2? Can anybody give me a step by step explanation from scratch with some sample code?<\/p>\n<p>Below is my repository class<\/p>\n<pre><code>namespace Mypro\\symBundle\\Entity;\n\nuse Doctrine\\ORM\\EntityRepository;\n\n\/**\n * RegisterRepository\n * This class was generated by the Doctrine ORM. Add your own custom\n * repository methods below.\n *\/\nclass RegisterRepository extends EntityRepository\n{\n\n\n    public function findAllOrderedByName()\n    {\n        return $this-&gt;getEntityManager()\n            -&gt;createQuery('SELECT p FROM symBundle:Register p ORDER BY p.name ASC')\n            -&gt;getResult();\n    }\n\n\n}\n<\/code><\/pre>\n<p>I called in my controller like this way<\/p>\n<pre><code>$em = $this-&gt;getDoctrine()-&gt;getEntityManager();\n          $pro = $em-&gt;getRepository('symBundle:Register')\n            -&gt;findAllOrderedByName();\n<\/code><\/pre>\n<p>I got the below error<\/p>\n<pre><code>Undefined method 'findAllOrderedByName'. The method name must start with either findBy or findOneBy!\n<\/code><\/pre>\n<p>Do I have any mistake in my code ? Any mistake in creating repository class? did i need to use any class.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi stackoverflow friends, I&#8217;m new in symfony2.I created a repository class when I created an entity class through command line.But I couldn&#8217;t access my custom functions in that repository class. how to create custom repository class in symfony2? Can anybody give me a step by step explanation from scratch with some sample code? Below is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6527","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6527","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6527"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6527\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6527"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6527"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6527"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}