CSS不能使用CakePHP,使用MAMP [英] CSS not working with CakePHP, using MAMP

查看:153
本文介绍了CSS不能使用CakePHP,使用MAMP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的MacBook Pro上使用MAMP作为本地服务器。 PHP和MySql运行良好。但是,我有一个奇怪的问题与CakePHP - CSS只适用于我的网站的主页,只有通过两个以下路径:
'localhost'和'localhost / index.php'



然而,使用'localhost / index.php /'只返回裸未标记的标记,网站中的所有其他页面。



一些搜索表明这可能是apache中的mod重写问题,但是我的深度真的 - 我不知道如何测试是否改变我改变模式重写。



由于CSS只适用于2个特定路径,它可能是一个我的路线的问题?我只有2定义 - '/'和'/index.php/' - 和他们都是一样的。



任何帮助将非常感激,
James

解决方案

问题很可能是因为tbwcf说你试图使用相对文件路径加载CSS文件,但您应该始终使用 CakePHP的帮助将资源文件添加到布局:

 <?php echo $ this-> Html-> css('style'); ?> 

上述输出

 < link rel =stylesheettype =text / csshref =/ css / style.css/>好处是,如果将应用程序安装到某个其他目录,路径会自动更改:

 < link rel =stylesheettype =text / csshref =/ other / directory / css / style.css /> 

不要 使用相对文件路径,例如。 ./css 。除非是最简单的情况,否则它会再次破坏布局。


i'm using MAMP on my MacBook Pro as a local server. PHP and MySql are running fine. However, i have a strange issue with CakePHP - CSS only works on homepage of my site and only by the two following paths: 'localhost' and 'localhost/index.php'

Using 'localhost/index.php/' however returns just the bare unstyled markup as does all other pages in the site. How can a slash a the end break the CSS?

A few searches have suggested this could possibly be a mod rewrite issue in apache, but i'm out of my depth to be honest - i don't know how to test if changes i make turn mod rewrite on.

As CSS works only for 2 specific paths, could it perhaps be a problems with my routes? I only have 2 defined - '/' and '/index.php/' - and they are both the same.

Any help will be greatly appreciated, James

解决方案

The problem is most likely as tbwcf says that you're trying to load the CSS files using relative file paths, but you should always use CakePHP's helpers to add resource files to the layout:

<?php echo $this->Html->css('style'); ?>

The above will output

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

The benefit is that if you install the app to some other directory the path changes automatically:

<link rel="stylesheet" type="text/css" href="/other/directory/css/style.css" />

Do not use relative file paths like ../css. It will break the layout again in all but the simplest cases.

这篇关于CSS不能使用CakePHP,使用MAMP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆