public function getDetail() { $rootDir = Yii::getAlias('@app'); $rootDir = dirname($rootDir); //remove last dir $viewsNormal = []; $viewsLayout = []; //$this->data = array_unique($this->data); //if delete duplicates foreach ($this->data as $view) { $viewFile = str_replace($rootDir.DIRECTORY_SEPARATOR, '', $view); if (strpos($viewFile, 'layouts') !== false) { $viewsLayout[$viewFile]++; } else { $viewsNormal[$viewFile]++; } } //Display $js = <<<JS function _openIDE(elem){ var xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", "http://localhost:63342/api/file?file=" + elem.innerHTML, true); xmlhttp.send(); } JS; $content = "<script>$js</script>"; $content .= 'Views:<ol>'; foreach ($viewsNormal as $v => $count) { $content .= '<li>' . $this->link2IDE($v) . ($count > 1 ? " ($count)" : '') . '</li>'; } $content .= '</ol>'; $content .= '<hr>on layout:<ol>'; foreach ($viewsLayout as $v => $count) { $content .= '<li>' . $this->link2IDE($v) . ($count > 1 ? " ($count)" : '') . '</li>'; } $content .= '</ol>'; return $content; }
private function link2IDE($linkFile) { //Variant 1 //$port = '63342'; //return Html::a($linkFile, "http://localhost:$port/api/file?file=$linkFile&line=1", ['target' => '_top']); //Variant 2 return "<a href='#' onclick='_openIDE(this);return false;'>$linkFile</a>"; }
return Yii::$app->view->render('@app/components/panels/views/auc/detail', [ 'data' => $this->data, ]);
Source: https://habr.com/ru/post/317562/
All Articles