dtt3399 2015-06-04 17:01
浏览 23
已采纳

链接正确时找不到样式表

I am trying to link my stylesheet to my php template for my website. I used the link: <link rel="stylesheet" type="text/css" href="{{app.request.basepath }}/App/views/templates/style.css">

Now, this works on my localhost server(I use MAMP), but when i upload the files to the web host I get the error:

Failed to load resource: the server responded with a status of 404 (Not Found)

The panel I have only seems to support up to 5.5, where as I use 5.6 on the local server. Could also be the issue.

And it also gives me a link, which is the exact link to the file, no misspelled or capitalized letters. The file I am trying to link the stylesheet to is in the same folder as the stylesheet. I am also rewriting the .htaccess file because I am using SlimPHP the file is:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

I think that this might have something to do with it being unable to link but i am not fully sure. Thanks in advance for all of your help

Edit: I fixed my problem by linking my style sheet to the public file in my directory. From there, I could link any images by using CSS, but also I had to place them in the public directory

  • 写回答

3条回答 默认 最新

  • dryb38654 2015-06-04 21:59
    关注

    This is how I route theme-specific stylesheets in Slim and Twig. First I create a new config variable, themes.path, that contains the actual filesystem path to my theme. Then I set up a route for css/theme.css:

    $app->config([
        'themes.path'    =>  "path/to/themes"
    ]);
    
    /* Render theme CSS */
    $app->get('/css/theme.css', function () use ($app) {
        $app->response->headers->set("Content-Type", "text/css");
        $css_include = $app->config('themes.path') . "/myTheme/css/theme.css";
        $app->response->setBody(file_get_contents($css_include));
    }    
    

    To use the theme stylesheet in my template documents, I simply do:

    <!-- Theme stylesheet -->
    <link rel="stylesheet" href="{{site.uri.css}}theme.css" type="text/css" >
    

    Where site.uri.css is a global template variable that contains the path to my (public) css directory. You can hardcode that part, if you prefer.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失