Advertisement
Guest User

Model User

a guest
Aug 17th, 2022
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. <?php
  2.  
  3. defined('BASEPATH') OR exit('No direct script access allowed');
  4.  
  5. class User_model extends MY_Model {
  6.  
  7.  
  8. public function getDefaultValues()
  9. {
  10. return [
  11. 'name' => '',
  12. 'email' => '',
  13. 'role' => '',
  14. 'is_active' => ''
  15. ];
  16. }
  17.  
  18. public function getValidationRules()
  19. {
  20. $validationRules = [
  21. [
  22. 'field' => 'name',
  23. 'label' => 'Nama',
  24. 'rules' => 'trim|required'
  25. ],
  26. [
  27. 'field' => 'email',
  28. 'label' => 'E-Mail',
  29. 'rules' => 'trim|required|valid_email|callback_unique_email'
  30. ],
  31. [
  32. 'field' => 'role',
  33. 'label' => 'Role',
  34. 'rules' => 'required'
  35. ],
  36. ];
  37. return $validationRules;
  38. }
  39.  
  40. public function uploadImage($fieldName, $fileName)
  41. {
  42. $config = [
  43. 'upload_path' => './images/user',
  44. 'file_name' => $fileName,
  45. 'allowed_types' => 'jpg|gif|png|jpeg|JPG|PNG',
  46. 'max_size' => 1024,
  47. 'max_width' => 0,
  48. 'max_height' => 0,
  49. 'overwrite' => true,
  50. 'file_ext_tolower' => true
  51. ];
  52.  
  53. $this->load->library('upload', $config);
  54.  
  55. if ($this->upload->do_upload($fieldName)) {
  56. return $this->upload->data();
  57. } else {
  58. $this->session->set_flashdata('image_error', $this->upload->display_errors('', ''));
  59. return false;
  60. }
  61. }
  62.  
  63. public function deleteImage($fileName)
  64. {
  65. if(file_exists("./images/user/$fileName"))
  66. {
  67. unlink("./images/user/$fileName");
  68. }
  69. }
  70.  
  71.  
  72. }
  73.  
  74. /* End of file User_model.php */
  75.  
  76. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement