I have searched lots of answers but none of them seem to help me. Basically, when I try loading my page, I get the error
Undefined method 'findTotalMatches'. The method name must start with either findBy or findOneBy!
So obviously Symfony2/Doctrine is not finding my custom repository class. My package structure is like so Nick/AlertBundle/ then all my other directories.
In my Entity class, I have
<?php
namespace Nick\AlertBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints\DateTime;
use Doctrine\Common\Collections\ArrayCollection;
/**
* AvailabilityAlert
*
* @ORM\Table(name="availability_alert")
* @ORM\Entity(repositoryClass="Nick\AlertBundle\Repository\AvailabilityAlertRepository")
*
*/
class AvailabilityAlert
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="search_command", type="string", length=256, nullable=false)
*/
private $searchCommand;
/**
* @var string
*
* @ORM\Column(name="is_connecting", type="string", length=20, nullable=false)
*/
private $isConnecting;
/**
* @var \DateTime
*
* @ORM\Column(name="last_updated", type="datetime", nullable=false)
*/
private $lastUpdated;
/**
* @var boolean
*
* @ORM\Column(name="is_deleted", type="boolean", nullable=false)
*/
private $isDeleted;
/**
* @var string
*
* @ORM\Column(name="alert_status", type="string", length=11, nullable=false)
*/
private $alertStatus;
}
So it is pointing to AvailabilityAlertRepository which is in my Repository directory. Using the command to generate this class didnt work for some reason (no error, just no class created) so I had to make it manually. All I am doing for testing purposes is
<?php
namespace Nick\AlertBundle\Repository;
use Doctrine\ORM\EntityRepository;
class AvailabilityAlertRepository extends EntityRepository
{
public function findTotalMatches($keyword)
{
return 34;
}
}
And then in my controller, I have
$keyword = "TEST";
$userRepo = $this->getDoctrine()->getRepository('NickAlertBundle:AvailabilityAlert');
var_dump($userRepo->findTotalMatches($keyword));
So everything from what I can see looks correct, however I still get the error mentioned at the beginning. I noticed some answers mentioned something about making sure that I am not using yml, not to sure how to check this though (and I have used annotations for everything else I think).
So am I missing something obvious here?
This is located at Resources/config/doctrine/AvailabilityAlert.orm.xml
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Nick\AlertBundle\Entity\AvailabilityAlert" table="availability_alert">
<id name="id" type="integer" column="id">
<generator strategy="IDENTITY"/>
</id>
<field name="searchCommand" type="string" column="search_command" length="256" nullable="false"/>
<field name="isConnecting" type="string" column="is_connecting" length="20" nullable="false"/>
<field name="lastUpdated" type="datetime" column="last_updated" nullable="false"/>
<field name="isDeleted" type="boolean" column="is_deleted" nullable="false"/>
<field name="alertStatus" type="string" column="alert_status" length="11" nullable="false"/>
</entity>
</doctrine-mapping>
Thanks