使用全局变量来包含css



我试图从全局变量中包含css,但不包括样式。

全球var:

<?php 
require_once '../app/init.php';
define('ROOT_DIR', dirname(__FILE__));
define('CSS_DIR', ROOT_DIR . 'css');
define('CSS_BOOTSTRAP', CSS_DIR . 'bootstrap.min.css');
define('CSS_STYLES', CSS_DIR . 'styles.css');       
$app = new App;
HTML:

<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <title>Bootstrap Login Form</title>
    <meta name="generator" content="Bootply" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
            <link href='<?php echo CSS_BOOTSTRAP; ?>' rel="stylesheet">
    <!--[if lt IE 9]>
        <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link href='<?php echo CSS_STYLES; ?>' rel="stylesheet">

</head>
<body>

浏览器代码:

<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <title>Bootstrap Login Form</title>
    <meta name="generator" content="Bootply" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
            <link rel="stylesheet" type="text/css" href="C:xampphtdocsgrade_your_roompubliccssbootstrap.min.css" >
    <!--[if lt IE 9]>
        <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="C:xampphtdocsgrade_your_roompubliccssstyles.css" >

</head>
<body>

如果我尝试访问路径C:xampphtdocsgrade_your_roompubliccssstyles.css样式可以显示

这是正常的dirname (https://secure.php.net/manual/en/function.dirname.php)在本地返回父目录的路径!

您应该将ROOT_DIR设置为您的域名(对于您的开发来说是localhost)。

<?php
require_once '../app/init.php';
define('ROOT_DIR', 'localhost');
define('CSS_DIR', ROOT_DIR . '/css');
define('CSS_BOOTSTRAP', CSS_DIR . '/bootstrap.min.css');
define('CSS_STYLES', CSS_DIR . '/styles.css'); 

最新更新