dsbckxk165039 2016-04-20 14:42
浏览 97
已采纳

php包含来自不同目录的.php和.html文件,不加载css和js

i have folders like this

\htdocsouter\index.php -> main index file
\htdocsouter\view\ -> all html and php files 
\htdocsouter\view\asset -> all css, js , etc files
\htdocsouter\controller\App\main.php -> controller file

Now when someone point to http://localhost, the index.php create new object (new main() ) from main.php (class main) and executes index function (public function index() { ... }) . This function have does an include like this ( require 'view/login.php'; ).

I can see the output of login.php but all .css, .jpg, .js files wont load because they are declared in login.php like this :

<link rel="stylesheed" href="asset/style.css" type="text/css">

because the asset/ directory is located where login.php file is.

if i put href="view/asset/style.css" it's working .

The question is :

How can i include a .php file from other folder to make it work without chaning the href tag and without moving the asset folder up.

  • 写回答

1条回答 默认 最新

  • dongyong6428 2016-04-20 14:58
    关注

    Actually, you can't make it work without changing href as assets refer to the root, not in the path.

    What you can do is make a symlink of view/asset to root, So it will assets will be accessible from both href="asset/style.css" and href="view/asset/style.css".

    Using PHP:

    symlink("view/asset","asset"); //index.php
    

    Or Terminal:

    ln -s view/asset asset
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型