首页 文章

致命错误:在 C:\ wamp\www\laravel-master\app\views\hello.php 中调用未定义的函数 asset()

提问于
浏览
3

我想学习 laravel 框架。我可以在我的 webserver(Wamp 中安装 laravel 并且我得到一些教程来学习它但是当我尝试在此路径中的 hello.php 文件位置添加样式到'h1'标签时:(“C: wampwwwlaravel-masterapp 通过 asset()函数查看\ hello.php“),发生上述错误。请帮我找出问题所在。这是 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>

和 main.css:

.highlight {
    border: solid 2px #F00; 
}

我的 laravel 版本是 4.2.16.

提前致谢。

5 回答

  • 1

    你可以尝试像{{ HTML::style('css/main.css') }}那样做

  • 1

    请注意,您可以使用纯 HTML:

    <link rel="stylesheet" type="text/css" href="/css/main.css" >
    
  • 1

    改变这一部分:

    <?php  echo asset('css/main.css'); ?>
    

    如下:

    /css/main.css
    
  • 1

    我正在使用 Laravel 版本 5.2

    我使用这个没问题:

    <!-- JavaScripts -->
        <script src="{{ asset('js/main.js') }}"></script>
    
  • 0

    今天我遇到了同样奇怪的情况。带有标准 bootstrap 和 jquery 链接的刀片文件正常工作,当添加 fullcalendar 时会触发该错误。删除 fullcalendar 再次正常工作,再次添加 fullcalendar,错误。这对我没有意义,因为没有 404 错误,只有"Call to undefined function asset()"

    我已经尝试用url()替换asset(),一切都按预期工作。

相关问题