Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何获取响应中包含的所有Laravel 5视图列表_Php_Laravel - Fatal编程技术网

Php 如何获取响应中包含的所有Laravel 5视图列表

Php 如何获取响应中包含的所有Laravel 5视图列表,php,laravel,Php,Laravel,我想知道是否有一种方法可以在响应中列出所有加载/包含/扩展的视图 我知道laravel debugbar,但出于单元测试的目的,我想从我的代码中执行它 只是想澄清一下:我不想列出我的资源文件夹中的所有视图。我想获得当前响应/请求中使用的所有视图的列表 谢谢 我也为自己做过类似的事情。这并不完美。使用函数创建以下路由: Route::get('list-views', function(){ $full_path = 'FULL-PATH-TO-YOUR-LARAVEL-VIEWS-FOL

我想知道是否有一种方法可以在响应中列出所有加载/包含/扩展的视图

我知道laravel debugbar,但出于单元测试的目的,我想从我的代码中执行它

只是想澄清一下:我不想列出我的资源文件夹中的所有视图。我想获得当前响应/请求中使用的所有视图的列表


谢谢

我也为自己做过类似的事情。这并不完美。使用函数创建以下路由:

  Route::get('list-views', function(){
  $full_path = 'FULL-PATH-TO-YOUR-LARAVEL-VIEWS-FOLDER'; //LIKE /home/account/www/resources/views/

  if(!is_dir($full_path))
    return 'Views directory not found';

  $files = scandir($full_path);
  unset($files[0]);
  unset($files[1]);

  if(($key = array_search('emails', $files)) !== false) {
    unset($files[$key]);
  }

  foreach($files AS $file){
    $link = str_replace('.blade.php','',$file);
    echo '<a href="'.$link.'">'.$link.'</a>'.'<br>';
  }
});
Route::get('list-views',function()){
$full_path='full-path-TO-YOUR-larvel-VIEWS-FOLDER';//LIKE/home/account/www/resources/VIEWS/
如果(!is_dir($full_path))
返回“未找到视图目录”;
$files=scandir($full_path);
未设置($files[0]);
未设置($files[1]);
if(($key=array\u search($email',$files))!==false){
取消设置($files[$key]);
}
foreach($files作为$file){
$link=str_replace('.blade.php','.$file);
回显''.
'; } });

此函数的作用是检查您在变量$full_path中定义的视图路径是否存在,并扫描该目录中的视图文件。现在,
列表视图
将列出所有可用视图

laravel debugbar可以做到这一点,但就我而言,我无法找到一种方法一次性列出同一url下的所有视图,因此,如果有人知道这一点,我将不胜感激

// EventServiceProvider@boot()

app('events')->listen('composing:*', function ($view, $data = []) {
    $url = url()->current();
    $view   = $data[0];
    $name   = $view->getName();
    $path = ltrim(str_replace(base_path(), '', realpath($view->getPath())), '/');

    logger([$url=>$path]);
});
另一种方式可能是,但这将只显示主视图“而不是嵌套或父视图”

您也可以从中间件获取视图,但这将只显示与b4相同的主视图

public function handle($request, Closure $next)
{
    $response = $next($request);

    $check = !$request->ajax() &&
        !$request->pjax() &&
        $request->isMethodCacheable() &&
        $response->isSuccessful();

    if ($check) {
        $view = $response->original;
        $path = ltrim(str_replace(base_path(), '', realpath($view->getPath())), '/');

        logger([$request->url(), $path]);
    }

    return $response;
}

谢谢你的代码。但我试图做的是列出在请求期间加载的所有视图。因此,如果我要转到路由“/test”,我希望看到路由返回响应时使用的所有视图。删除了我的答案,很抱歉,我不知道您想要的方式。@aqq Aw:(您不必这样做。可能有人发现它很有帮助。哦,现在取消删除!)
public function handle($request, Closure $next)
{
    $response = $next($request);

    $check = !$request->ajax() &&
        !$request->pjax() &&
        $request->isMethodCacheable() &&
        $response->isSuccessful();

    if ($check) {
        $view = $response->original;
        $path = ltrim(str_replace(base_path(), '', realpath($view->getPath())), '/');

        logger([$request->url(), $path]);
    }

    return $response;
}