2011-01-04 4 views
0

J'ai un problème de bits avec Smarty, Zend et l'encodage gzip, j'étend la classe SmartySmarty Template Engine et Gzip encodage

//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 ... dans mon index.tpl i appeler la fonction { site-> header} et mon navigateur Chrome jeter l'erreur:

Server error. 

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

j'ai essayé de charger avec fetch comme:

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

mais j'ai la même erreur, lorsque je supprime le site de sortie de remplissage est en cours d'exécution.

Si quelqu'un peut m'aider, je l'apprécierais grandement. Désolé si mon anglais n'est pas très bon. Merci d'avance.

+0

Ne pas utiliser Smarty. PHP est déjà un langage de modèle et Zend_View vous donne une bonne façon de l'utiliser. – mfonda

Répondre

0

Je suis d'accord avec mfonda, n'utilisez pas Smarty.

J'utilise utiliser cette classe de plug-in pour gzip toute ma réponse du corps en cas de besoin:

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

Notez l'utilisation de dispatchLoopShutdown en raison de this post.

La classe a été adaptée à partir this post j'ai trouvé en utilisant Google

+0

Ok, j'ai enlevé le smarty de mon système. – Alex

Questions connexes