SHARE
TWEET

Untitled

a guest Jun 20th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top