当前位置: 首页>>代码示例>>PHP>>正文


PHP Repository::findOneBy方法代码示例

本文整理汇总了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());
 }
开发者ID:foothing,项目名称:laravel-repository,代码行数:10,代码来源:EloquentRepositoryTest.php

示例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;
 }
开发者ID:jardarn,项目名称:UKMokonomi,代码行数:28,代码来源:ProjectService.php

示例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;
 }
开发者ID:jardarn,项目名称:UKMokonomi,代码行数:30,代码来源:SubProjectService.php


注:本文中的Repository::findOneBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。