本文整理汇总了PHP中Repository::findOneBy方法的典型用法代码示例。如果您正苦于以下问题:PHP Repository::findOneBy方法的具体用法?PHP Repository::findOneBy怎么用?PHP Repository::findOneBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Repository
的用法示例。
在下文中一共展示了Repository::findOneBy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDetach
public function testDetach()
{
$homer = $this->repository->findOneBy('name', 'Homer');
$father = Role::find(1);
$this->assertEquals(1, $homer->roles->count());
$homer = $this->repository->detach($homer, 'roles', $father);
// Refresh.
$homer->load('roles');
$this->assertEquals(0, $homer->roles->count());
}
示例2: create
/**
* Create project
*
* @param string $name
* @param User $owner
*
* @return project
*/
public function create($name, $owner, $budget, $description = '')
{
if (empty($name)) {
throw new Exception('Project name cannot be empty!', 2000);
}
$this->_validateOwner($owner);
$this->_validateBudget($budget);
// Existing name
$existing = $this->repo->findOneBy(array('name' => $name, 'budget' => $budget));
if (!is_null($existing)) {
throw new Exception('Project name already registered within budget ("' . $budget->getName() . '")!', 2001);
}
$project = new project();
$project->setName($name);
$project->setOwner($owner->getId());
$project->setBudget($budget);
$project->setDescription($description);
$this->_persistAndFlush($project);
return $project;
}
示例3: create
/**
* Create SubProject
*
* @param string $name
* @param User $owner
*
* @return SubProject
*/
public function create($name, $project, $description = '')
{
if (empty($name)) {
throw new Exception('SubProject name cannot be empty!', 2000);
}
$this->_validateProject($project);
// Existing name
$existing = $this->repo->findOneBy(array('name' => $name, 'project' => $project));
if (!is_null($existing) && $project->getId() != 0) {
throw new Exception('SubProject name already registered within project ("' . $project->getName() . '::' . $name . '")!', 2001);
}
$budgetRepo = $this->doctrine->getRepository('UKMecoBundle:Budget');
$budget = $budgetRepo->findOneById($project->getBudget());
$this->_validateBudget($budget);
$subProject = new SubProject();
$subProject->setName($name);
$subProject->setProject($project);
$subProject->setBudget($budget);
$subProject->setDescription($description);
$this->_persistAndFlush($subProject);
return $subProject;
}