Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Weird smarty problem

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
AnteD
Smarty Regular


Joined: 14 Dec 2004
Posts: 38

PostPosted: Tue Jan 23, 2007 2:50 pm    Post subject: Weird smarty problem Reply with quote

Ok..I'm not a noob in using smarty..have been using it for years now but lately I have experienced a weird problem...

Here is the thing..

I have Smarty in a root directory where all other domains are ..for example

Code:
root->
   -> somedomain.com
   -> otherdomain.com
   -> thirddomain.net
   -> classes
             ->Smarty


So smarty is "outside" of "domains"...now I have a class Template which just extends Smarty and it looks like this...

Code:
class Template extends Smarty {
   
   /**
    * Constructor...
    *
    * @return void
    */
   public function __construct() {
      parent::Smarty();
      $this->caching = false;
      $this->template_dir = SMARTY_TEMPLATE_DIR;
      $this->compile_dir = SMARTY_DIR ."templates_c";
      $this->clear_compiled_tpl();

   }
}


Ok..the problem is that "sometimes" when some page under some domain reloads the page itself is displayed corrupted (read: it breaks all over the browser..when you refresh it's gone and everything is ok) but the problem is that the "template" shown will be from another project.....I call them "ghost" pages....I could live with that but the problem I just saw was that on one page the "ghost" page was from their competition (also on our server) which is NOT nice ofcourse...why is this happening and what is causing those "ghost" pages? (there is not any pattern when they appear..but when they do you see a corrupted template from another project..you reload and it's ok again)...

I really do hope I made this clear as this is a strange problem...
Back to top
View user's profile Send private message
TGKnIght
Smarty Junkie


Joined: 07 Sep 2005
Posts: 580
Location: Philadelphia, PA

PostPosted: Tue Jan 23, 2007 3:01 pm    Post subject: Reply with quote

Well.. issue might be that you are clearing your templates every call to any of your websites since you are using a common compile_dir.

I would suggest using a unique compile_id for each site, since they each have their own template_dir, but possibly have templates of the same name.
http://smarty.php.net/manual/en/variable.compile.id.php

In this example I just used the hash of the servername.. You can modify that line to make it as unique as you need...

Then you can also remove the clear_compiled_tpl() call... This is killing your processing time if you do this for every page.

Code:

class Template extends Smarty {
   
   /**
    * Constructor...
    *
    * @return void
    */
   public function __construct() {
      parent::Smarty();
      $this->caching = false;
      $this->template_dir = SMARTY_TEMPLATE_DIR;
      $this->compile_dir = SMARTY_DIR ."templates_c";
      $this->compile_id = sha1($_SERVER['SERVER_NAME']);
   }
}

_________________
Smarty site with one index.php controller file
Working with MySQL and Smarty
SmartyColumnSort
Custom Smarty Javascript Debug Template
Back to top
View user's profile Send private message Visit poster's website
AnteD
Smarty Regular


Joined: 14 Dec 2004
Posts: 38

PostPosted: Tue Jan 23, 2007 3:28 pm    Post subject: Reply with quote

Thanx man Smile

I though noone would even understand the problem Smile

So basicly I just have to use unique id per DOMAIN if I got this right?

Because using your example
$this->compile_id = sha1($_SERVER['SERVER_NAME']);

will always generate the same hash as the domains are on the same server(server_name = 'localhost') ...

How about using a BASEURL constant? because it holds www.domainname.com and than sha1-it? How that sounds? Or did I completely misunderstood the point....
Back to top
View user's profile Send private message
TGKnIght
Smarty Junkie


Joined: 07 Sep 2005
Posts: 580
Location: Philadelphia, PA

PostPosted: Tue Jan 23, 2007 3:41 pm    Post subject: Reply with quote

Yes, the whole point is you need to create a unique ID for each site IF you are using the same compile and/or cache directories for multiple sites..

FYI $_SERVER['SERVER_NAME'] returns the HOST HEADER used to connect to your site... So it is not the physical server... it is the domain name used to connect to that server ie somedomain.com

So yeah if you're doing it all through http://localhost for some reason then there is gonna be an issue.

You could use one of your own constants sure... or perhaps

$this->compile_id = sha1($_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']);
_________________
Smarty site with one index.php controller file
Working with MySQL and Smarty
SmartyColumnSort
Custom Smarty Javascript Debug Template
Back to top
View user's profile Send private message Visit poster's website
AnteD
Smarty Regular


Joined: 14 Dec 2004
Posts: 38

PostPosted: Wed Jan 24, 2007 7:48 am    Post subject: Reply with quote

Once again thax..

You made my day.... Smile
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP