當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。