Guest User

Untitled

a guest
Jun 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. <?php
  2. class Projects_model extends Model
  3. {
  4.  
  5. private $_tbl = 'projects';
  6.  
  7. .......
  8.  
  9. // This works for my regular update
  10. public function updateProject( $id, $project )
  11. {
  12. $this->db->where( 'id', $id );
  13. $this->db->update( $this->_tbl, $project );
  14. }
  15.  
  16. // Entry point
  17. public function addMainFileUrls()
  18. {
  19. $inputs = $this->cleanMainFileInputs();
  20. $id = array_shift( $inputs );
  21. $this->updateProject( $id, $inputs );
  22. }
  23.  
  24. // Cleans up posted info before passing back to addMainFileUrls
  25. private function cleanMainFileInputs()
  26. {
  27. $inputs = array( 'project_id' => 'id',
  28. 'plans_file' => 'plans_url',
  29. 'specs_file' => 'specs_url' );
  30.  
  31. $cleanUrls = array();
  32. foreach ($inputs as $key => $newKey) {
  33. $cleanUrls[$newKey] = $this->input->post($key);
  34. }
  35. return $cleanUrls;
  36. }
  37. }
  38.  
  39.  
  40.  
  41.  
  42. <?php
  43.  
  44. class Projects extends Controller {
  45.  
  46. ......
  47.  
  48. public function files()
  49. {
  50. $this->projects->addMainFileUrls();
  51. redirect('/projects');
  52. }
  53.  
  54.  
  55. ......
  56.  
  57. }
  58.  
  59. ------------------------------------------------------
  60.  
  61. var_dump of info going to Projects_model::updateProject()
  62.  
  63. var_dump of $id = string(1) "2"
  64.  
  65. var_dump of $inputs = array(2) {
  66. ["plans_url"]=>
  67. string(10) "A-3.07.pdf"
  68. ["specs_url"]=>
  69. string(10) "A-4.04.pdf"
  70. }
  71.  
  72. -----------------------------------------------------
  73.  
  74. Updated row in the database:
  75.  
  76. plans_url = A-3.07.pdf
  77. specs_url = 0
Add Comment
Please, Sign In to add comment