Smarty Template Engine и кодировка Gzip - PullRequest
0 голосов
/ 05 января 2011

У меня небольшая проблема с кодировкой smarty, Zend и gzip, я расширяю класс smarty

//This method i call in one front controller plugin
$this->getResponse()->setHeader('Content-Encoding' , 'gzip');

View extends Zend_View_Abstract implements Zend_View_Interface {

   public $_smarty;

   public function __construct(){

      $this->_smarty = new Smarty();
      //Hire i have some smarty options paths and etc.
      //------------------
      //I register this object to smarty template
      $this->_smarty->registerObject('Smarty', $this);

      //You can see this pulugin at this address
      //http://smarty.incutio.com/?page=GZipPlugin
      $this->_smarty->loadFilter('output', 'gzip');

   }


   public function Fetch($tpl){
      retutn $this->_smarty->fetch($tpl);
   }

   //Zend call this method after loaded controller and display active controller tpl
   public function Render($tpl){
      retutn $this->_smarty->display($tpl);
   }

   public function Header($params, &$smarty){
      $this->_smarty->display('header.tpl');
   }


}

ОК ... в моем index.tpl я вызываю функцию {Site-> header}и мой браузер Chrome выдает ошибку:

Server error.

The website encountered an error while retrieving http://site.dev. It may be down for maintenance or configured incorrectly.

Я пытался загрузить с извлечением, как:

echo $this->_smarty->fetch('header.tpl');

, но у меня та же ошибка, когда я удаляю наполнитель Out Putсайт работает.

Если кто-нибудь может мне помочь, я был бы очень признателен.Извините, если мой английский не очень хорош.Заранее спасибо.

1 Ответ

0 голосов
/ 05 января 2011

Я согласен с mfonda, не используйте Smarty.

Я использую этот класс плагинов для Gzip моего полного ответа тела при необходимости:

class Lib_Controller_Plugin_Gzip extends Zend_Controller_Plugin_Abstract
{
    public function dispatchLoopShutdown()
    {
        $content = $this->getResponse()->getBody();

        $content = preg_replace(
                    array('/(\x20{2,})/',   '/\t/', '/\n\r/'),
                    array(' ',      ' ',    ' '),
                    $content
                );

        if (@strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') === FALSE) 
            $this->getResponse()->setBody($content);
        else 
        {
            header('Content-Encoding: gzip');
            $this->getResponse()->setBody(gzencode($content, 9));
        }
    }
}

Обратите внимание на использование dispatchLoopShutdown из-за этого поста .

Класс был адаптирован с этого поста Я нашел с помощью Google

...