簡體   English   中英

致命錯誤:在C:\\ wamp \\ www \\ laravel-master \\ app \\ views \\ hello.php中調用未定義的函數asset()

[英]Fatal error: Call to undefined function asset() in C:\wamp\www\laravel-master\app\views\hello.php

我想學習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>

和main.css:

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

而我的laravel版本是4.2.16。

提前致謝。

改變這一部分:

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

如下:

/css/main.css

您可以像{{ HTML::style('css/main.css') }}一樣嘗試這樣做

請注意,您可以使用純HTML:

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

我正在使用Laravel 5.2版

我使用這個沒問題:

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

今天我遇到了同樣奇怪的情況。 帶有標准bootstrap和jquery鏈接的刀片文件正常工作,當添加fullcalendar時會觸發該錯誤。 刪除fullcalendar再次正常工作,再次添加fullcalendar,錯誤。 這對我沒有意義,因為沒有404錯誤,只是"Call to undefined function asset()"

我嘗試用url()替換asset() ,一切都按預期工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM