我对 Assets 类有一些问题,无法缩小和组合我的 css 和 js。我有这个插件广告,它似乎可以正常工作:
class Plugin_Theme_Assets extends Plugin
{
/**
* combine and insert multiple js files
*
* usage:
* { theme_assets:js_files files="file1.js,file2.js" }
*/
function js_files()
{
$files = $this->attribute('files');
preg_match_all('/[w-.]+.js/i', $files, $files_a);
foreach($files_a[0] as $file)
{
Asset::js($file);
}
return Asset::render_js();
}
/**
* combine and insert multiple css files
*
* usage:
* { theme_assets:css_files files="file1.css,file2.css" }
*/
function css_files()
{
$files = $this->attribute('files');
preg_match_all('/[w-.]+.css/i', $files, $files_a);
foreach($files_a[0] as $file)
{
Asset::css($file);
}
return Asset::render_css();
}
}
这是我的 .htaccess 文件,正如您可以 si 我已经取消注释 SetEnv:
# Multiple Environment config
# Set this to development, staging or production
SetEnv PYRO_ENV production
<IfModule mod_rewrite.c>
# Make sure directory listing is disabled
Options +FollowSymLinks -Indexes
RewriteEngine on
# NOTICE: If you get a 404 play with combinations of the following commented out lines
#AllowOverride All
RewriteBase /
# Restrict your site to only one domain
# !important USE ONLY ONE OPTION
# Option 1: To rewrite "www.domain.com -> domain.com" uncomment the following lines.
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Option 2: To rewrite "domain.com -> www.domain.com" uncomment the following lines.
#RewriteCond %{HTTPS} !=on
#RewriteCond %{HTTP_HOST} !^www..+$ [NC]
#RewriteCond %{HTTP_HOST} (.+)$ [NC]
#RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
# Remove index.php from URL
#RewriteCond %{HTTP:X-Requested-With} !^XMLHttpRequest$
#RewriteCond %{THE_REQUEST} ^[^/]*/index.php [NC]
#RewriteRule ^index.php(.*)$ $1 [R=301,NS,L]
# Keep people out of codeigniter directory and Git/Mercurial data
RedirectMatch 403 ^/(system/cms/cache|system/codeigniter|.git|.hg).*$
# Send request via index.php (again, not if its a real file or folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
</IfModule>
所以,如果我是对的,现在PYRO_ENV是"生产"。
如果我刷新我的页面,css 和 js 文件不会缩小并合并为一个文件......这是插件返回的内容
<link href="http://example:8888/addons/default/themes/mytheme/css/nivo-slider.css" rel="stylesheet" type="text/css" />
<link href="http://example:8888/addons/default/themes/mytheme/css/default.css" rel="stylesheet" type="text/css" />
你能帮帮我吗?
如果您的主机不允许在 .htaccess 中SetEnv
,您可以使用重写规则发送环境变量:
RewriteCond %{HTTP_HOST} ^local.yoursite.com$
RewriteRule (.*) $1 [E=PYRO_ENV:development]
RewriteCond %{HTTP_HOST} ^beta.yoursite.com$
RewriteRule (.*) $1 [E=PYRO_ENV:staging]
RewriteCond %{HTTP_HOST} ^yoursite.com$
RewriteRule (.*) $1 [E=PYRO_ENV:production]
默认情况下,资产缩小和合并将在生产或暂存系统上进行,开发环境不会出于开发/调试目的进行缩小和合并。您可以在system/cms/config/asset.php
中覆盖此功能以进行测试。
这是你自己写的插件,对吧? 我很困惑为什么在文档中你建议人们使用{ theme_assets:css_files files="file1.css,file2.css" }
,而你可以这样做而根本不需要自定义插件:
{{ asset:css file="file1.css" }}
{{ asset:css file="file2.css" }}
{{ asset:render }}
(也是的,一旦你正确设置了环境,它应该就可以工作了(你也可以修改/system/cms/config/asset.php进行测试)。
问题是我的托管,它不允许我在 .htaccess 中使用SetEnv