0

この関数を使用して、cakephp 1.3にアップロードした後、csvをmysqlにインポートしました

function uploadCsv(){
    if (!empty($this->data)) {
        $csvFile = $this->Upload->csvUpload('files/assessments/csv', $this->data['Assessment']['csv']);// upload avata and the image path to the form array; ready to be served
       // unset($this->data['Assessment']['csv']);
            if(isset($csvFile['path'])) {
                 $file = $csvFile['path'];
                    $delimiter = ',';
                       if (($handle = fopen($file, "r")) !== FALSE) { 
                        $i = 0; 
                        while (($lineArray = fgetcsv($handle, 4000, $delimiter)) !== FALSE) { 
                            for ($j=0; $j<count($lineArray); $j++) { 
                                $data2DArray[$i][$j] = $lineArray[$j]; 
                                } 
                            $i++; 
                            } 
                            fclose($handle); 
                        } 
                        //return $data2DArray;$i = 0;
                        foreach($data2DArray as $csv){
                            $this->data['Assessment'][$i]['id'] = '';
                            $this->data['Assessment'][$i]['test1'] = $csv[0];
                            $this->data['Assessment'][$i]['test2'] = $csv[1];
                            $this->data['Assessment'][$i]['ass1'] = $csv[2];
                            $this->data['Assessment'][$i]['ass2'] = $csv[3];
                            $this->data['Assessment'][$i]['ass3'] = $csv[4];
                            $this->data['Assessment'][$i]['ca1'] = $csv[5];
                            $this->data['Assessment'][$i]['ca2'] = $csv[6];
                            $this->data['Assessment'][$i]['exams'] = $csv[7];
                            $this->data['Assessment'][$i]['total'] = $csv[8];
                            $this->data['Assessment'][$i]['subject_id'] = $csv[9];
                            $this->data['Assessment'][$i]['student_id'] = $csv[10];
                            $this->data['Assessment'][$i]['my_classes_student_id'] = $csv[11];
                            $i++;
                            }
                    $this->Assessment->create();
                        if ($this->Assessment->saveAll($this->data['Assessment'])) {
                            $this->Session->setFlash(__('The assessment has been saved', true));
                            //$this->redirect(array('action' => 'index'));
                        } else {
                            $this->Session->setFlash(__('The assessment could not be saved. Please, try again.', true));
                        }
            $this->set('data', $this->data['Assessment']);

        }else{

            $this->set('errors', $csvFile['errors']);

            }

    }// end of $thid->data check
}

しかし、私はこのエラーが発生しました:

Fatal Error
Error: ReflectionClass::getProperties() [<a href='http://php.net/reflectionclass.getproperties'>reflectionclass.getproperties</a>]:
Internal error: Failed to retrieve the reflection object
File: C:\wamp\www\csm\lib\Cake\Utility\Debugger.php
Line: 593

Notice: If you want to customize this error message, create app\View\Errors\fatal_error.ctp

Cakephp 2.3にアップグレードした後

これについて助けが必要です。

4

1 に答える 1

0

ありがとう、答えはありませんでしたが、誰かが同様の問題を抱えていると思います.cakephp 2.3は$this->dataの代わりに$this->request->dataを使用しているので、単に$this->dataを$this->request-に変更しました>データとそれが機能し始めた

function uploadCsv(){
    if (!empty($this->data)) {
        $csvFile = $this->Upload->csvUpload('files/assessments/csv', $this->data['Assessment']['csv']);// upload avata and the image path to the form array; ready to be served
       unset($this->request->data['Assessment']['csv']);
            if(isset($csvFile['path'])) {
                 $file = $csvFile['path'];
                    $delimiter = ',';
                       if (($handle = fopen($file, "r")) !== FALSE) { 
                        $i = 0; 
                        while (($lineArray = fgetcsv($handle, 4000, $delimiter)) !== FALSE) { 
                            for ($j=0; $j<count($lineArray); $j++) { 
                                $data2DArray[$i][$j] = $lineArray[$j]; 
                                } 
                            $i++; 
                            } 
                            fclose($handle); 


                        } 
                        //return $data2DArray;
                        $i = 0;
                        foreach($data2DArray as $csv){
                            $this->request->data['Assessment'][$i]['id'] = '';
                            $this->request->data['Assessment'][$i]['test1'] = $csv[0];
                            $this->request->data['Assessment'][$i]['test2'] = $csv[1];
                            $this->request->data['Assessment'][$i]['ass1'] = $csv[2];
                            $this->request->data['Assessment'][$i]['ass2'] = $csv[3];
                            $this->request->data['Assessment'][$i]['ass3'] = $csv[4];
                            $this->request->data['Assessment'][$i]['ca1'] = $csv[5];
                            $this->request->data['Assessment'][$i]['ca2'] = $csv[6];
                            $this->request->data['Assessment'][$i]['exams'] = $csv[7];
                            $this->request->data['Assessment'][$i]['total'] = $csv[8];
                            $this->request->data['Assessment'][$i]['subject_id'] = $csv[9];
                            $this->request->data['Assessment'][$i]['student_id'] = $csv[10];
                            $this->request->data['Assessment'][$i]['my_classes_student_id'] = $csv[11];
                            $i++;
                            }

                $this->Assessment->create();
                        if ($this->Assessment->saveAll($this->data['Assessment'])) {
                            $this->Session->setFlash(__('The assessment has been saved', true));
                            //$this->redirect(array('action' => 'index'));
                        } else {
                            $this->Session->setFlash(__('The assessment could not be saved. Please, try again.', true));
                        }
            $this->set('data', $this->data['Assessment']);

        }else{

            $this->set('errors', $csvFile['errors']);

            }

    }// end of $thid->data check
}
于 2013-03-06T00:42:46.617 に答える