致命错误:调用 C:\wamp\www\laravel-master\app\views\hello.php 中未定义的函数 asset()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29716694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fatal error: Call to undefined function asset() in C:\wamp\www\laravel-master\app\views\hello.php
提问by Javad
I wanted to learn laravel framework. I could install laravel in my webserver(Wamp) and i get some tutorial to learn it but when i tryed to add style to 'h1' tag in the hello.php file place in this path:("C:\wamp\www\laravel-master\app\views\hello.php") by asset() function, above mentioned error occurred. please help me to find out where the problem are. here is hello.php codes:
我想学习laravel框架。我可以在我的网络服务器(Wamp)中安装 laravel 并且我得到了一些教程来学习它但是当我尝试将样式添加到 hello.php 文件中的 'h1' 标签时,位于此路径中:("C:\wamp\www\ laravel-master\app\views\hello.php") 通过 asset() 函数,出现上述错误。请帮我找出问题所在。这是 hello.php 代码:
<style>
body {
margin:0;
font-family:'Lato', sans-serif;
text-align:center;
color: #999;
}
.welcome {
width: 300px;
height: 200px;
position: absolute;
left: 50%;
top: 50%;
margin-left: -150px;
margin-top: -100px;
}
a, a:visited {
text-decoration:none;
}
h1 {
font-size: 32px;
margin: 16px 0 0 0;
}
</style>
</head>
<link rel="stylesheet" type="text/css" href="<?php echo asset('css/main.css'); ?>" >
<body>
<div class="welcome">
<a href="http://laravel.com" title="Laravel PHP Framework"> <img src="some_long_src" alt="Laravel PHP Framework"></a>
<h1 class="highlight">You have arrived.</h1>
</div>
</body>
</html>
and main.css :
和 main.css :
.highlight {
border: solid 2px #F00;
}
and my laravel version is 4.2.16.
我的 Laravel 版本是 4.2.16。
thanks in advance.
提前致谢。
回答by Gujarat Santana
I'm using Laravel version 5.2
我正在使用 Laravel 5.2 版
and I've no problem using this :
我使用这个没有问题:
<!-- JavaScripts -->
<script src="{{ asset('js/main.js') }}"></script>
回答by mirza
Change this part:
改变这部分:
<?php echo asset('css/main.css'); ?>
as this:
像这样:
/css/main.css
回答by apelsinka223
You can try to do it like {{ HTML::style('css/main.css') }}
你可以尝试这样做 {{ HTML::style('css/main.css') }}
回答by KyleK
Note that you can use pure HTML:
请注意,您可以使用纯 HTML:
<link rel="stylesheet" type="text/css" href="/css/main.css" >
回答by Farid
Today I've run in the same strange situation. A blade file with standard bootstrap & jquery links working fine as usual, when added fullcalendar fires that error.
Removing fullcalendar works fine again, adding fullcalendar, error again.
It makes no sense to me because there is no 404 error, just "Call to undefined function asset()"
今天我也遇到了同样奇怪的情况。带有标准引导程序和 jquery 链接的刀片文件照常工作,当添加 fullcalendar 时会触发该错误。删除 fullcalendar 再次正常工作,添加 fullcalendar,再次出错。这对我来说毫无意义,因为没有 404 错误,只是"Call to undefined function asset()"
I've tried replacing asset()
with url()
and everything works as expected.
我试过替换asset()
为url()
,一切都按预期工作。