获取传递到Laravel View Composer的视图位置 [英] Get location of view passed into laravel view composer

查看:79
本文介绍了获取传递到Laravel View Composer的视图位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以获取传递到Laravel视图编辑器中的视图的位置?

Is it possible to get the location of a view that is passed into a Laravel view composer?

View::composer('*', function($view) {
   // I want to find out the location of the view file here
   // e.g. master.something.header
   // then add this to an array
   $loadedViews = View::share("loadedViews");
   $loadedViews[] = $thisViewName;
});

原因是我想拥有一个将在视图之间共享的变量,并且包含所有已加载的视图的数组.任何css和js文件都将位于与视图匹配的目录结构中.

The reason is that I want to have a variable that will be shared between views and contain an array of all the views that are loaded. Any css and js files will be located in directory structure that matches the views one.

这意味着我可以创建一个css和js视图,然后在页面上包含所需的css和js文件.所有的CSS和js都将直接链接到特定的视图.

This means I can then have a css and js view which then include the required css and js files for the views on the page. All css and js will be directly linked to a specific view.

如果已经可以执行此操作,或者可以获取已加载视图的列表,请告诉我!

If there is already a way to do this, or a way to get a list of loaded views, please let me know!

推荐答案

$view->getName()是我想要的答案.

$view->getPath()是文件的实际路径.

这篇关于获取传递到Laravel View Composer的视图位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆