Commit 852ac6bc1c0028e5eb8f9bc3c839801792406a5f
1 parent
cc37b5ec
user registration
Showing
3 changed files
with
24 additions
and
1 deletions
Show diff stats
app/library/App/Controllers/UserController.php
| ... | ... | @@ -3,6 +3,7 @@ |
| 3 | 3 | namespace App\Controllers; |
| 4 | 4 | |
| 5 | 5 | use PhalconRest\Mvc\Controllers\CrudResourceController; |
| 6 | +use Phalcon\Mvc\Model; | |
| 6 | 7 | |
| 7 | 8 | class UserController extends CrudResourceController |
| 8 | 9 | { |
| ... | ... | @@ -83,4 +84,24 @@ class UserController extends CrudResourceController |
| 83 | 84 | return $response; |
| 84 | 85 | |
| 85 | 86 | } |
| 87 | + | |
| 88 | + protected function createItem(Model $item, $data) | |
| 89 | + { | |
| 90 | + $this->beforeAssignData($item, $data); | |
| 91 | + $item->assign($data, null, $this->whitelistCreate()); | |
| 92 | + $this->afterAssignData($item, $data); | |
| 93 | + | |
| 94 | + $this->beforeSave($item); | |
| 95 | + $this->beforeCreate($item); | |
| 96 | + | |
| 97 | + $success = $item->create(); | |
| 98 | + | |
| 99 | + if ($success) { | |
| 100 | + | |
| 101 | + $this->afterCreate($item); | |
| 102 | + $this->afterSave($item); | |
| 103 | + } | |
| 104 | + | |
| 105 | + return $success ? $item : null; | |
| 106 | + } | |
| 86 | 107 | } | ... | ... |
app/library/App/Model/User.php
| ... | ... | @@ -4,6 +4,7 @@ namespace App\Model; |
| 4 | 4 | |
| 5 | 5 | class User extends \App\Mvc\DateTrackingModel |
| 6 | 6 | { |
| 7 | + public $id; | |
| 7 | 8 | public $role; |
| 8 | 9 | public $firstName; |
| 9 | 10 | public $lastName; |
| ... | ... | @@ -18,6 +19,7 @@ class User extends \App\Mvc\DateTrackingModel |
| 18 | 19 | public function columnMap() |
| 19 | 20 | { |
| 20 | 21 | return parent::columnMap() + [ |
| 22 | + 'id' => 'id', | |
| 21 | 23 | 'role' => 'role', |
| 22 | 24 | 'email' => 'email', |
| 23 | 25 | 'username' => 'username', | ... | ... |
app/library/App/Transformers/UserTransformer.php