|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
AnteD Smarty Regular
Joined: 14 Dec 2004 Posts: 38
|
Posted: Tue Jan 23, 2007 2:50 pm Post subject: Weird smarty problem |
|
|
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 |
|
TGKnIght Smarty Junkie
Joined: 07 Sep 2005 Posts: 580 Location: Philadelphia, PA
|
Posted: Tue Jan 23, 2007 3:01 pm Post subject: |
|
|
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 |
|
AnteD Smarty Regular
Joined: 14 Dec 2004 Posts: 38
|
Posted: Tue Jan 23, 2007 3:28 pm Post subject: |
|
|
Thanx man
I though noone would even understand the problem
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 |
|
TGKnIght Smarty Junkie
Joined: 07 Sep 2005 Posts: 580 Location: Philadelphia, PA
|
Posted: Tue Jan 23, 2007 3:41 pm Post subject: |
|
|
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 |
|
AnteD Smarty Regular
Joined: 14 Dec 2004 Posts: 38
|
Posted: Wed Jan 24, 2007 7:48 am Post subject: |
|
|
Once again thax..
You made my day.... |
|
Back to top |
|
|
|
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
|