当前位置: 首页>>代码示例>>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;未经允许,请勿转载。