dsbckxk165039 2016-04-20 06: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 06: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 代写uni代码,app唤醒
  • ¥15 全志t113i启动qt应用程序提示internal error
  • ¥15 ensp可以看看嘛.
  • ¥80 51单片机C语言代码解决单片机为AT89C52是清翔单片机
  • ¥60 优博讯DT50高通安卓11系统刷完机自动进去fastboot模式
  • ¥15 minist数字识别
  • ¥15 在安装gym库的pygame时遇到问题,不知道如何解决
  • ¥20 uniapp中的webview 使用的是本地的vue页面,在模拟器上显示无法打开
  • ¥15 网上下载的3DMAX模型,不显示贴图怎么办
  • ¥15 关于#stm32#的问题:寻找一块开发版,作为智能化割草机的控制模块和树莓派主板相连,要求:最低可控制 3 个电机(两个驱动电机,1 个割草电机),其次可以与树莓派主板相连电机照片如下:
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部