Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. $data = $this->request->data['csv'];
  2.  
  3. $file = $data['tmp_name'];
  4. $handle = fopen($file, "r");
  5. $data=[];
  6. while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) {
  7.  
  8. if($row[0] == 'id') {
  9. continue;
  10. }
  11. $data[]=$row;
  12. // $Subcategories = $this->Subcategories->newEntity();
  13. $subcategory = $this->Subcategories->newEntity();
  14. $coloum = [
  15. 'name' => $row[1],
  16. 'category_id' => $row[0],
  17. 'title' => $row[2],
  18. 'status' => $row[3]
  19. ];
  20.  
  21. // $subcategory = $this->Subcategories->patchEntity($subcategory,$coloum);
  22.  
  23.  
  24.  
  25. }
  26. //echo "<pre>";print_R($coloum);die;
  27. $subcategory = $this->Subcategories->patchEntity($subcategory,$coloum);
  28.  
  29. if ($this->Subcategories->save($subcategory)) {
  30. return $this->redirect(['action' => 'index']);
  31. }else{
  32. print_r($data);
  33. }
  34. //fclose($handle);
  35. // $this->set('title','Upload Student CSV File Input Number and others');
  36. //return $this->redirect($this->referer());
  37. return $this->redirect(['action' => 'index']);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement