symfony2 中 .js 文件中的 Web 目录和资产的路径
我正在谷歌搜索,但找不到我需要的东西。
如何在
操作中获取symfony2中“web”目录的路径[不知道,我只找到了旧版本symfony的解决方案:
$sf_relative_url_root = sfContext::getInstance()->getRequest()->getRelativeUrlRoot();
我也尝试过 $this->get('security.context')->getRequest()->getRelativeUrlRoot(),但它不起作用].js 文件
如果是 .js 文件,我现在在 twig 模板中执行类似的操作:
<script type="text/javascript">
var asset_url="{{asset(' ')}}";
asset_url = asset_url.substr(0, asset_url.length-1);
</script>
<script href="{{asset('js/script.js')}}" type="text/javascript"></script>
是更好的方法吗?
I'm googling and googling and can't find what I need.
How to get path to "web" directory in symfony2 in
action [no idea, i only found solution for older versions of symfony:
$sf_relative_url_root = sfContext::getInstance()->getRequest()->getRelativeUrlRoot();
I've tried also $this->get('security.context')->getRequest()->getRelativeUrlRoot(), but it doesn't work].js file
In case of .js file I do for now in twig template something like that:
<script type="text/javascript">
var asset_url="{{asset(' ')}}";
asset_url = asset_url.substr(0, asset_url.length-1);
</script>
<script href="{{asset('js/script.js')}}" type="text/javascript"></script>
is a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解你的问题,那么你要寻找的是控制器类中的
$this->getRequest()->getUri()
。查看
Symfony\Component\HttpFoundation\Request
类,如果没有,您很可能会在那里找到它。If I understood your question correctly, then what you're looking for is
$this->getRequest()->getUri()
in a controller class.Take a look at
Symfony\Component\HttpFoundation\Request
class if it's not, you will most likely find it there.