PyroCMS - 资产类不会缩小和组合

时间:2012-06-29 14:51:24

标签: .htaccess pyrocms

我在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文件,因为你可以取消注释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" />

你能帮帮我吗?

3 个答案:

答案 0 :(得分:3)

如果您的托管在.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中覆盖此内容以进行测试。

答案 1 :(得分:1)

这是你自己写的插件,对吗?我很困惑,为什么在你建议人们使用{ 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 进行测试)。

答案 2 :(得分:0)

问题是我的托管,它不允许我在.htaccess中使用SetEnv