2011-01-04 12 views
0

私はSmartyのとビットの問題をした、Zendのとgzipエンコーディングは、私は私が機能{呼び出す私のindex.tplでSmartyのテンプレートエンジンとgzipエンコーディング

//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'); 
    } 


} 

[OK]を... Smartyのクラスを拡張しますサイト - >ヘッダ} と私のブラウザのクロームは、エラーをスロー:

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

Server error. 

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

私は好きフェッチとロードしようとしました

でも、アウトパットサイトを削除すると同じエラーが発生します。

誰かが私を助けることができれば、私は大いに感謝しています。 申し訳ありませんが、私の英語はあまり良くありません。 ありがとうございます。

+0

Smartyは使用しないでください。 PHPはすでにテンプレート言語であり、Zend_Viewはあなたに使いやすい方法を提供します。 – mfonda

答えて

0

私は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)); 
     } 
    } 
} 

は理由this postdispatchLoopShutdownの使用に注意してください。

クラスはthis postから適応されましたGoogleを使用して見つかりました

+0

私のシステムからsmartyを削除しました。 – Alex

関連する問題