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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看