Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $data = $this->request->data['csv'];
- $file = $data['tmp_name'];
- $handle = fopen($file, "r");
- $data=[];
- while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) {
- if($row[0] == 'id') {
- continue;
- }
- $data[]=$row;
- // $Subcategories = $this->Subcategories->newEntity();
- $subcategory = $this->Subcategories->newEntity();
- $coloum = [
- 'name' => $row[1],
- 'category_id' => $row[0],
- 'title' => $row[2],
- 'status' => $row[3]
- ];
- // $subcategory = $this->Subcategories->patchEntity($subcategory,$coloum);
- }
- //echo "<pre>";print_R($coloum);die;
- $subcategory = $this->Subcategories->patchEntity($subcategory,$coloum);
- if ($this->Subcategories->save($subcategory)) {
- return $this->redirect(['action' => 'index']);
- }else{
- print_r($data);
- }
- //fclose($handle);
- // $this->set('title','Upload Student CSV File Input Number and others');
- //return $this->redirect($this->referer());
- return $this->redirect(['action' => 'index']);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement