0

我对 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" />

你能帮我么?

4

3 回答 3

3

如果您的主机不允许SetEnv在 .htaccess 中,您可以使用重写规则发送环境变量:

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出于测试目的覆盖它。

于 2012-11-03T18:07:44.673 回答
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进行测试)。

于 2012-08-15T22:05:17.313 回答
0

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

于 2012-08-17T14:06:27.373 回答