custom repository class in symfony2
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 Custom Repository Classes in Symfony2
You don't need the "getNumberOfTasks" method at all.
What you should be doing is specifying the associations in your Doctrine Entities.
You can read about it here:
http://doctrine-orm.readthedocs.org/en/latest/reference/association-mapping.html
Based on your naming, I would suspect a OneToMany relationship from Project to Task, and a ManyToOne relationship from Task to Project.
When mapped correctly, in Twig you can then use:
{{ project.tasks|length }}
to get the number of tasks in a project. All you need to do is to pass the Project Entity to Twig and Symfony will handle the rest, including loading in all relationships.This is the best way of doing what you are trying to do.
Custom repository class in symfony 2 not working
Thanks for everyone who was helping. I figured it out, IT WAS MYSELF of course there was nothing wrong with symfony but much more with what I did:
After the command:
php app/console generate:bundle --namespace=Acme/StoreBundle
I choose for"Determine the format to use for the generated configuration." --> xml
And not annotation. So I had to change in my~/Projects/Symfony/src/Acme/StoreBundle/Resources/config/doctrine/Product.orm.xml
file. the <entity name="Acme\StoreBundle\Entity\Product">
to<entity
name="Acme\StoreBundle\Entity\Product"
repository-class="Acme\StoreBundle\Entity\ProductRepository">
How to use a custom repository in Symfony?
The problem was that I declared my function as private instead of public
private function findByTitle($term){
instead ofpublic function findByTitle($term){
Related Topics
Remove Extra Spaces But Not Space Between Two Words
Callback Function Using Variables Calculated Outside of It
Php:Capturing the Command Output
PHP Character Encoding Problems
How to Encrypt HTML Source Code Output Using PHP
Replacing Backslashes with Forward Slashes with Str_Replace() in PHP
PHP Datetime::Createfromformat Doesn't Parse Iso 8601 Date Time
Check If Youtube and Vimeo-Clips Are Valid
How to Remove All Dtddwrappers and Labels on Zend Form Elements
Running PHP 5.4 Built-In Web Server Outside Localhost
Php-Paypal-Error: 14077410:Ssl Routines:Ssl23_Get_Server_Hello:Sslv3 Alert Handshake Failure
PHP - Good Cronjob/Crontab/Cron Tutorial or Book
Force Download via Ajax and PHP
Codeigniter Compatibility with PHP Version