Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Using applyFilter for updates
- Users::applyFilter('save', function($self, $params, $chain) {
- if ($params['data']) {
- $params['entity']->set($params['data']);
- $params['data'] = array();
- }
- if (!$params['entity']->exists()) {
- $params['entity']->password = Password::hash($params['entity']->password);
- }
- return $chain->next($self, $params, $chain);
- });
- $user = Users::first($id);
- if (!empty($this->request->data) && !empty($user)) {
- if ($user->save($this->request->data)) {
- // woohoo
- } else {
- // bummer
- }
- }
- Users::applyFilter('save', function($self, $params, $chain) {
- if ($params['data']) {
- $params['entity']->set($params['data']);
- $params['data'] = array();
- }
- $entity = $params['entity'];
- if ($entity->password) {
- $export = $entity->export();
- if (empty($export['data']['password']) || $export['data']['password'] != $entity->password) {
- $entity->password = Password::hash($entity->password);
- }
- }
- return $chain->next($self, $params, $chain);
- });
Add Comment
Please, Sign In to add comment