public function actionRoot() { $model = new UploadFile(); if (Yii::$app->request->isPost) { // Загрузка пост параметров в модель $model->load(Yii::$app->request->post()); $model->file = UploadedFile::getInstance($model, 'file'); //print'<pre>'; print_r($model->file); print'</pre>'; if ($model->upload()) { // Скрипт $data = Sorting::root('uploads/' . $model->file->name, $model->text, $error); // file is uploaded successfully return $this->render('root', ['model' => $model, 'data' => $data, 'error' => isset($error) ? $error : false]); } } return $this->render('root', ['model' => $model, 'data' => $data]); }
public function root($file, $text, &$error) { $num = 0; $files = scandir('uploads/'); //print'<pre>'; print_r($files); print'</pre>'; // Получили массив строк $array = Sorting::getDataFile($file); // Всего строк $num_all = count ($array); // Получили массив корней $keys = explode (' ', $text); // Создаем массив результата /*foreach ($keys as $key){ } */ foreach ($array as $position => $val){ //print'<pre>'; //print_r($val); //print'</pre>'; foreach ($keys as $key){ // Если получено вхождение if (strripos($val[6], $key) !== false){ // Сохраняем корень и его строку $result[$key][] = $val; // Количество совпадений $num++; // Удаляет переменную unset ($array[$position]); // Останавливает перебор break; } } } //print'<pre>'; //print_r(array_merge(array_flip($keys),$result)); //print'</pre>'; // Осталось строк $num_end = count ($array); if ($num_all>$num){ $error['text'] = 'Всего '.$num_all.' строк. <br>Определено '.$num.' строк. <br>Не определено '.($num_end).' строк.'; $error['items'] = $array; } //print'23'; //print'<pre>'; print_r($result); print'</pre>'; return array_merge(array_flip($keys),$result); //$result; }