public function add()
    {
        $this->loadModel('User.Users');
        $user = $this->Users->newEntity();
        $user = $this->Users->attachFields($user);
        $languages = LocaleToolbox::languagesList();
        $roles = $this->Users->Roles->find('list', [
            'conditions' => [
                'id NOT IN' => [ROLE_ID_AUTHENTICATED, ROLE_ID_ANONYMOUS]
            ]
        ]);

        if ($this->request->data()) {
            $user->accessible('id', false);
            $data = $this->request->data;

            if (isset($data['welcome_message'])) {
                $sendWelcomeMessage = (bool)$data['welcome_message'];
                unset($data['welcome_message']);
            } else {
                $sendWelcomeMessage = false;
            }

            $user = $this->Users->patchEntity($user, $data);
            if ($this->Users->save($user)) {
                if ($sendWelcomeMessage) {
                    NotificationManager::welcome($user)->send();
                }

                $this->Flash->success(__d('user', 'User successfully registered!'));
                $this->redirect(['plugin' => 'User', 'controller' => 'manage', 'action' => 'edit', $user->id]);
            } else {
                $this->Flash->danger(__d('user', 'User could not be registered, please check your information.'));
            }
        }

        $this->title(__d('user', 'Register New User'));
        $this->set(compact('user', 'roles', 'languages'));
        $this->Breadcrumb->push('/admin/user/manage');
    }
public function add()
    {
        $this->loadModel('User.Users');
        $user = $this->Users->newEntity();
        $user = $this->Users->attachFields($user);
        $languages = LocaleToolbox::languagesList();
        $roles = $this->Users->Roles->find('list', [
            'conditions' => [
                'id NOT IN' => [ROLE_ID_AUTHENTICATED, ROLE_ID_ANONYMOUS]
            ]
        ]);

        if ($this->request->data()) {
            $user->accessible('id', false);
            $data = $this->request->data;

            if (isset($data['welcome_message'])) {
                $sendWelcomeMessage = (bool)$data['welcome_message'];
                unset($data['welcome_message']);
            } else {
                $sendWelcomeMessage = false;
            }

            $user = $this->Users->patchEntity($user, $data);
            if ($this->Users->save($user)) {
                if ($sendWelcomeMessage) {
                    NotificationManager::welcome($user)->send();
                }

                $this->Flash->success(__d('user', 'User successfully registered!'));
                $this->redirect(['plugin' => 'User', 'controller' => 'manage', 'action' => 'edit', $user->id]);
            } else {
                $this->Flash->danger(__d('user', 'User could not be registered, please check your information.'));
            }
        }

        $this->title(__d('user', 'Register New User'));
        $this->set(compact('user', 'roles', 'languages'));
        $this->Breadcrumb->push('/admin/user/manage');
    }
public function add ( ) { $ this -> loadModel ( 'User.Users' ) ; $ user = $ this -> Users -> newEntity ( ) ; $ user = $ this -> Users -> attachFields ( $ user ) ; $ languages = LocaleToolbox :: languagesList ( ) ; $ roles = $ this -> Users -> Roles -> find ( 'list' , [ 'conditions' => [ 'id NOT IN' => [ ROLE_ID_AUTHENTICATED , ROLE_ID_ANONYMOUS ] ] ] ) ; if ( $ this -> request -> data ( ) ) { $ user -> accessible ( 'id' , false ) ; $ data = $ this -> request -> data ; if ( isset ( $ data [ 'welcome_message' ] ) ) { $ sendWelcomeMessage = ( bool ) $ data [ 'welcome_message' ] ; unset ( $ data [ 'welcome_message' ] ) ; } else { $ sendWelcomeMessage = false ; } $ user = $ this -> Users -> patchEntity ( $ user , $ data ) ; if ( $ this -> Users -> save ( $ user ) ) { if ( $ sendWelcomeMessage ) { NotificationManager :: welcome ( $ user ) -> send ( ) ; } $ this -> Flash -> success ( __d ( 'user' , 'User successfully registered!' ) ) ; $ this -> redirect ( [ 'plugin' => 'User' , 'controller' => 'manage' , 'action' => 'edit' , $ user -> id ] ) ; } else { $ this -> Flash -> danger ( __d ( 'user' , 'User could not be registered, please check your information.' ) ) ; } } $ this -> title ( __d ( 'user' , 'Register New User' ) ) ; $ this -> set ( compact ( 'user' , 'roles' , 'languages' ) ) ; $ this -> Breadcrumb -> push ( '/admin/user/manage' ) ; }
Adds a new user.

@return void
Adds a new user .