Среда:
"require": {
"php": "5.6",
"zendframework/zendframework": "2.5.0",
"zendframework/zend-servicemanager": "2.5.1",
"zendframework/zend-developer-tools": "1.0.0",
"doctrine/doctrine-orm-module": "0.9.2",
"acelaya/zf2-acmailer": "4.*",
"tasmaniski/zend-params-helper": "^1.0"
}
Неустранимая ошибка: необработанное исключение 'Zend \ Stdlib \ Exception \ BadMethodCallException' с сообщением 'У опции "filters" нет вызываемого "setFilters" ("setfilters"") метод установки, который должен быть определен" в C: \ OSPanel \ domains \ csmCrew_github \ vendor \ zendframework \ zend-servicemanager \ src \ ServiceManager.php в строке 1135
Я пытаюсь добавить SQLфильтр с использованием этого учебника по DareDevels
мой интерфейс: VacanciesFilterInterface.php
namespace Common\DoctrineFilter;
Interface VacanciesFilterInterface
{
public function setFilters($filters);
}
мой класс фильтрации: VacanciesFilter.php
namespace Common\DoctrineFilter;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Query\Filter\SQLFilter;
class VacanciesFilter extends SQLFilter
{
/**
* Gets the SQL query part to add to a query.
*
* @param ClassMetaData $targetEntity
* @param string $targetTableAlias
*
* @return string The constraint SQL if there is available, empty string otherwise.
*/
public function addFilterConstraint (ClassMetadata $targetEntity, $targetTableAlias)
{
// Check if the entity implements the LocalAware interface
if (!$targetEntity->reflClass->implementsInterface('\Common\DoctrineFilter\VacanciesFilterInterface')) {
return '';
}
return $targetTableAlias.'.Vacancies = ' . $this->getParameter('Vacancies'); // getParameter applies quoting automatically
}
my module.config.php:
'doctrine' => array(
'driver' => array(
// defines an annotation driver with two paths, and names it `my_annotation_driver`
'common_entity' => array(
'class' => \Doctrine\ORM\Mapping\Driver\AnnotationDriver::class,
'cache' => 'array',
'paths' => array(
__DIR__ . '/../src/Common/Entity',
__DIR__ . '/../src/Common/Entity/Repository',
),
),
// default metadata driver, aggregates all other drivers into a single one.
// Override `orm_default` only if you know what you're doing
'orm_default' => array(
'drivers' => array(
// register `my_annotation_driver` for any entity under namespace `My\Namespace`
'Common\Entity' => 'common_entity',
),
'filters' => array(
'vacancies' => 'Common\DoctrineFilter\VacanciesFilter',
),
),
),
),
Я добавляю фильтр в свой контроллер, используя следующие методы:
public function enableVacanciesFilter()
{
$em = $this->getEntityManager();
$filter = $em->getFilters()->enable('vacancies');
$filter->setParameter('vacancies', '41');
}
/**
* Disable locale filter
*/
public function disableVacanciesFilter()
{
$em = $this->getEntityManager();
$filter = $em->getFilters()->disable('vacancies');
}
Итак, вопрос: как я могу реализовать этот вызываемый метод setFilters setter??Я пытался реализовать интерфейс в моей сущности:
<?php
namespace Common\Entity;
use Common\DoctrineFilter\VacanciesFilterInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* Vacancies
*
* @ORM\Table(name="vacancies", indexes={@ORM\Index(name="RankId_fk", columns={"rank_id"}), @ORM\Index(name="id", columns={"id"}), @ORM\Index(name="FK_vacancies_crewing_companies", columns={"company_id"}), @ORM\Index(name="FK_vacancies_vessels", columns={"vessel_id"}), @ORM\Index(name="FK_vacancies_vacancy_positions", columns={"position"}), @ORM\Index(name="status_id", columns={"status_id"})})
* @ORM\Entity
*/
class Vacancies implements VacanciesFilterInterface
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=128, nullable=false)
*/
private $title = '';
/**
* @var string
*
* @ORM\Column(name="additional_info", type="string", length=255, nullable=false)
*/
private $additionalInfo = '';
/**
* @var integer
*
* @ORM\Column(name="duration_of_contract_in_months", type="smallint", nullable=false)
*/
private $durationOfContractInMonths;
/**
* @var \DateTime
*
* @ORM\Column(name="joining_date", type="date", nullable=false)
*/
private $joiningDate;
/**
* @var integer
*
* @ORM\Column(name="salary_per_month", type="integer", nullable=false)
*/
private $salaryPerMonth;
/**
* @var boolean
*
* @ORM\Column(name="required_age_from", type="boolean", nullable=false)
*/
private $requiredAgeFrom;
/**
* @var boolean
*
* @ORM\Column(name="required_age_to", type="boolean", nullable=false)
*/
private $requiredAgeTo;
/**
* @var \DateTime
*
* @ORM\Column(name="creation_date", type="datetime", nullable=false)
*/
private $creationDate;
/**
* @var integer
*
* @ORM\Column(name="views_count", type="integer", nullable=true)
*/
private $viewsCount = '0';
/**
* @var integer
*
* @ORM\Column(name="job_seekers_applied", type="integer", nullable=true)
*/
private $jobSeekersApplied = '0';
/**
* @var boolean
*
* @ORM\Column(name="is_published", type="boolean", nullable=false)
*/
private $isPublished = '0';
/**
* @var \Common\Entity\CrewingCompanies
*
* @ORM\ManyToOne(targetEntity="Common\Entity\CrewingCompanies")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="company_id", referencedColumnName="id")
* })
*/
private $company;
/**
* @var \Common\Entity\VacancyPositions
*
* @ORM\ManyToOne(targetEntity="Common\Entity\VacancyPositions")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="position", referencedColumnName="id")
* })
*/
private $position;
/**
* @var \Common\Entity\Vessels
*
* @ORM\ManyToOne(targetEntity="Common\Entity\Vessels")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="vessel_id", referencedColumnName="id")
* })
*/
private $vessel;
/**
* @var \Common\Entity\Ranks
*
* @ORM\ManyToOne(targetEntity="Common\Entity\Ranks")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="rank_id", referencedColumnName="id")
* })
*/
private $rank;
/**
* @var \Common\Entity\VacancyStatuses
*
* @ORM\ManyToOne(targetEntity="Common\Entity\VacancyStatuses")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="status_id", referencedColumnName="id")
* })
*/
private $status;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
*
* @return Vacancies
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set additionalInfo
*
* @param string $additionalInfo
*
* @return Vacancies
*/
public function setAdditionalInfo($additionalInfo)
{
$this->additionalInfo = $additionalInfo;
return $this;
}
/**
* Get additionalInfo
*
* @return string
*/
public function getAdditionalInfo()
{
return $this->additionalInfo;
}
/**
* Set durationOfContractInMonths
*
* @param integer $durationOfContractInMonths
*
* @return Vacancies
*/
public function setDurationOfContractInMonths($durationOfContractInMonths)
{
$this->durationOfContractInMonths = $durationOfContractInMonths;
return $this;
}
/**
* Get durationOfContractInMonths
*
* @return integer
*/
public function getDurationOfContractInMonths()
{
return $this->durationOfContractInMonths;
}
/**
* Set joiningDate
*
* @param \DateTime $joiningDate
*
* @return Vacancies
*/
public function setJoiningDate($joiningDate)
{
$this->joiningDate = $joiningDate;
return $this;
}
/**
* Get joiningDate
*
* @return \DateTime
*/
public function getJoiningDate()
{
return $this->joiningDate;
}
/**
* Set salaryPerMonth
*
* @param integer $salaryPerMonth
*
* @return Vacancies
*/
public function setSalaryPerMonth($salaryPerMonth)
{
$this->salaryPerMonth = $salaryPerMonth;
return $this;
}
/**
* Get salaryPerMonth
*
* @return integer
*/
public function getSalaryPerMonth()
{
return $this->salaryPerMonth;
}
/**
* Set requiredAgeFrom
*
* @param boolean $requiredAgeFrom
*
* @return Vacancies
*/
public function setRequiredAgeFrom($requiredAgeFrom)
{
$this->requiredAgeFrom = $requiredAgeFrom;
return $this;
}
/**
* Get requiredAgeFrom
*
* @return boolean
*/
public function getRequiredAgeFrom()
{
return $this->requiredAgeFrom;
}
/**
* Set requiredAgeTo
*
* @param boolean $requiredAgeTo
*
* @return Vacancies
*/
public function setRequiredAgeTo($requiredAgeTo)
{
$this->requiredAgeTo = $requiredAgeTo;
return $this;
}
/**
* Get requiredAgeTo
*
* @return boolean
*/
public function getRequiredAgeTo()
{
return $this->requiredAgeTo;
}
/**
* Set creationDate
*
* @param \DateTime $creationDate
*
* @return Vacancies
*/
public function setCreationDate($creationDate)
{
$this->creationDate = $creationDate;
return $this;
}
/**
* Get creationDate
*
* @return \DateTime
*/
public function getCreationDate()
{
return $this->creationDate;
}
/**
* Set viewsCount
*
* @param integer $viewsCount
*
* @return Vacancies
*/
public function setViewsCount($viewsCount)
{
$this->viewsCount = $viewsCount;
return $this;
}
/**
* Get viewsCount
*
* @return integer
*/
public function getViewsCount()
{
return $this->viewsCount;
}
/**
* Set jobSeekersApplied
*
* @param integer $jobSeekersApplied
*
* @return Vacancies
*/
public function setJobSeekersApplied($jobSeekersApplied)
{
$this->jobSeekersApplied = $jobSeekersApplied;
return $this;
}
/**
* Get jobSeekersApplied
*
* @return integer
*/
public function getJobSeekersApplied()
{
return $this->jobSeekersApplied;
}
/**
* Set isPublished
*
* @param boolean $isPublished
*
* @return Vacancies
*/
public function setIsPublished($isPublished)
{
$this->isPublished = $isPublished;
return $this;
}
/**
* Get isPublished
*
* @return boolean
*/
public function getIsPublished()
{
return $this->isPublished;
}
/**
* Set company
*
* @param \Common\Entity\CrewingCompanies $company
*
* @return Vacancies
*/
public function setCompany(\Common\Entity\CrewingCompanies $company = null)
{
$this->company = $company;
return $this;
}
/**
* Get company
*
* @return \Common\Entity\CrewingCompanies
*/
public function getCompany()
{
return $this->company;
}
/**
* Set position
*
* @param \Common\Entity\VacancyPositions $position
*
* @return Vacancies
*/
public function setPosition(\Common\Entity\VacancyPositions $position = null)
{
$this->position = $position;
return $this;
}
/**
* Get position
*
* @return \Common\Entity\VacancyPositions
*/
public function getPosition()
{
return $this->position;
}
/**
* Set vessel
*
* @param \Common\Entity\Vessels $vessel
*
* @return Vacancies
*/
public function setVessel(\Common\Entity\Vessels $vessel = null)
{
$this->vessel = $vessel;
return $this;
}
/**
* Get vessel
*
* @return \Common\Entity\Vessels
*/
public function getVessel()
{
return $this->vessel;
}
/**
* Set rank
*
* @param \Common\Entity\Ranks $rank
*
* @return Vacancies
*/
public function setRank(\Common\Entity\Ranks $rank = null)
{
$this->rank = $rank;
return $this;
}
/**
* Get rank
*
* @return \Common\Entity\Ranks
*/
public function getRank()
{
return $this->rank;
}
/**
* Set status
*
* @param \Common\Entity\VacancyStatuses $status
*
* @return Vacancies
*/
public function setStatus(\Common\Entity\VacancyStatuses $status = null)
{
$this->status = $status;
return $this;
}
/**
* Get status
*
* @return \Common\Entity\VacancyStatuses
*/
public function getStatus()
{
return $this->status;
}
public function setFilters ($filters)
{
$this->filters = $filters;
// TODO: Implement setFilters() method.
}
}
Но с этой ошибкой ничего не помогает.