Advertisement
Guest User

Untitled

a guest
Mar 9th, 2019
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. function add_Employee(){
  2.  
  3. $accounts=$this->User->find('list', array(
  4. 'fields'=>array('account_id'),
  5. 'conditions' => array(
  6. 'User.id' => $this->Auth->user('id'))));
  7.  
  8. if($this->request->is('post')){
  9. $this->User->create();
  10. if ($this->User->save($this->request->data))
  11. {
  12. $this->Session->setFlash('The user has been saved');
  13. $this->redirect( array('controller'=>'Users','action' => 'index_admin'));
  14. }
  15. else { $this->Session->setFlash('The user could not be saved. Please, try again.'); }
  16. }
  17. $this->set('accounts',$accounts);
  18.  
  19.  
  20. }
  21.  
  22. <h2>Add Employee</h2>
  23. <p>Add a new Employee here, please enter their details below.</p>
  24. <?php
  25. echo $this->Form->create('User', array('action'=>'add_Employee'));
  26. echo $this->Form->input('username',array('label'=>'Username: '));
  27. echo $this->Form->input('password',array('label'=>'Password: '), array('type'=>'password'));
  28. echo $this->Form->input('password_confirmation',array('label'=>'Confirm: '), array('type'=>'password'));
  29. echo $this->Form->input('email',array('label'=>'Email: '));
  30. echo $this->Form->input('title',array('label'=>'Title: '));
  31. echo $this->Form->input('firstname',array('label'=>'First Name: '));
  32. echo $this->Form->input('surname',array('label'=>'Surname: '));
  33. echo $this->Form->input('active', array('default'=>true, 'type'=>'hidden'));
  34. echo $this->Form->input('account_id', array('value'=>$accounts['User']['account_id']));
  35. echo $this->Form->input('access_level', array(
  36. 'label' => 'Access Level:',
  37. 'options' => array('1'=>'Employee','2'=>'Adminstrator')));
  38. echo $this->Form->end('Submit');
  39. ?>
  40.  
  41. In controller:
  42.  
  43. $accounts=$this->User->find('first', array(
  44. 'conditions' => array(
  45. 'id' => $this->Auth->user('id'))));
  46. $this->set('account',$accounts);
  47.  
  48. In view :
  49. echo $this->Form->input('account_id', array('label'=>'Account','value'=>$account['User']['account_id']));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement