當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::findFirstById方法代碼示例

本文整理匯總了PHP中app\models\User::findFirstById方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::findFirstById方法的具體用法?PHP User::findFirstById怎麽用?PHP User::findFirstById使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\models\User的用法示例。


在下文中一共展示了User::findFirstById方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: runAction

 /**
  * @return Response
  * @throws UserException
  */
 public function runAction()
 {
     /** @var User $user */
     $user = User::findFirstById($this->getId());
     if ($user) {
         return $this->response($user);
     } else {
         throw new UserException('User not found', 404);
     }
 }
開發者ID:alevikzs,項目名稱:phrest-app,代碼行數:14,代碼來源:ViewController.php

示例2: runAction

 /**
  * @return Response
  * @throws UserException
  */
 public function runAction()
 {
     $user = User::findFirstById($this->getId());
     if ($user) {
         $user->delete();
         return $this->response($user);
     } else {
         throw new UserException('User not found', 404);
     }
 }
開發者ID:alevikzs,項目名稱:phrest-app,代碼行數:14,代碼來源:DeleteController.php

示例3: testMain

 public function testMain()
 {
     /** @var User $userToDelete */
     $userToDelete = $this->getStub()->offsetGet(0);
     $response = $this->delete('/user/' . $userToDelete->getId());
     $responsePayload = $response->json();
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertTrue($responsePayload['success']);
     $this->assertNull($responsePayload['meta']);
     $this->assertEquals($responsePayload['data']['id'], $userToDelete->getId());
     $this->assertEquals($responsePayload['data']['name'], $userToDelete->getName());
     $this->assertEquals($responsePayload['data']['email'], $userToDelete->getEmail());
     /** @var User|boolean $deletedUser */
     $deletedUser = User::findFirstById($userToDelete->getId());
     $this->assertFalse($deletedUser);
 }
開發者ID:alevikzs,項目名稱:phrest-app,代碼行數:16,代碼來源:DeleteTest.php

示例4: testMain

 public function testMain()
 {
     $userFixture = (new UserFixture())->getArray('Create Test');
     $response = $this->post('/user', $userFixture);
     $responsePayload = $response->json();
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertTrue($responsePayload['success']);
     $this->assertNull($responsePayload['meta']);
     $this->assertEquals($responsePayload['data']['name'], $userFixture['name']);
     $this->assertEquals($responsePayload['data']['email'], $userFixture['email']);
     /** @var boolean|User $createdUser */
     $createdUser = User::findFirstById($responsePayload['data']['id']);
     $this->assertNotFalse($createdUser);
     $this->assertEquals($userFixture['name'], $createdUser->getName());
     $this->assertEquals($userFixture['email'], $createdUser->getEmail());
     $isValidPassword = (new Security())->checkHash($userFixture['password'], $createdUser->getPassword());
     $this->assertTrue($isValidPassword);
 }
開發者ID:alevikzs,項目名稱:phrest-app,代碼行數:18,代碼來源:CreateTest.php

示例5: testPasswordNotChange

 public function testPasswordNotChange()
 {
     /** @var User $userToUpdate */
     $userToUpdate = $this->getStub()->offsetGet(0);
     $userFixture = (new UserFixture())->getArray('Update Test');
     unset($userFixture['password']);
     $response = $this->put('/user/' . $userToUpdate->getId(), $userFixture);
     $responsePayload = $response->json();
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertTrue($responsePayload['success']);
     $this->assertNull($responsePayload['meta']);
     $this->assertEquals($responsePayload['data']['name'], $userFixture['name']);
     $this->assertEquals($responsePayload['data']['email'], $userFixture['email']);
     /** @var User|boolean $userAfterUpdate */
     $userAfterUpdate = User::findFirstById($responsePayload['data']['id']);
     $this->assertNotFalse($userAfterUpdate);
     $this->assertEquals($userFixture['name'], $userAfterUpdate->getName());
     $this->assertEquals($userFixture['email'], $userAfterUpdate->getEmail());
     $this->assertEquals($userToUpdate->getPassword(), $userAfterUpdate->getPassword());
 }
開發者ID:alevikzs,項目名稱:phrest-app,代碼行數:20,代碼來源:UpdateTest.php

示例6: runAction

 /**
  * @return Response
  * @throws UserException
  */
 public function runAction()
 {
     $user = User::findFirstById($this->getId());
     if ($user) {
         $name = $this->getPayload()->getName();
         if (!is_null($name)) {
             $user->setName($name);
         }
         $email = $this->getPayload()->getEmail();
         if (!is_null($email)) {
             $user->setEmail($email);
         }
         $password = $this->getPayload()->getPassword();
         if (!is_null($password)) {
             $user->setPassword($password);
         }
         $user->save();
         return $this->response($user);
     } else {
         throw new UserException('User not found', 404);
     }
 }
開發者ID:alevikzs,項目名稱:phrest-app,代碼行數:26,代碼來源:UpdateController.php


注:本文中的app\models\User::findFirstById方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。