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

Smarty itself works, but caching doesn't despite of settings

 
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
FractalizeR
Smarty Rookie


Joined: 01 Nov 2003
Posts: 16

PostPosted: Sat Nov 01, 2003 11:14 am    Post subject: Smarty itself works, but caching doesn't despite of settings Reply with quote

Hello to all!
I have problems with caching using Smarty. Here is my source code, I'm trying to execute:

[php:1:0f3207c303]<?php
define('SMARTY_DIR', $HTTP_SERVER_VARS['DOCUMENT_ROOT'].'/smarty/');
require($HTTP_SERVER_VARS['DOCUMENT_ROOT'].'/smarty/Smarty.class.php');
error_reporting(E_ALL);
$Smarty=new Smarty;
$cur_lang = 'en';
if (isset($HTTP_GET_VARS['lang']))
{$cur_lang = $HTTP_GET_VARS['lang'];}
elseif (isset($HTTP_COOKIE_VARS['lang']) and (strlen($HTTP_COOKIE_VARS['lang'])==2))
{$cur_lang = $HTTP_COOKIE_VARS['lang'];}

setcookie('lang',$cur_lang);

$Smarty->template_dir=str_replace('//','/',$HTTP_SERVER_VARS['DOCUMENT_ROOT'].'/');
$Smarty->caching_dir=str_replace('//','/',$HTTP_SERVER_VARS['DOCUMENT_ROOT'].'/cached/');
$Smarty->compile_dir=str_replace('//','/',$HTTP_SERVER_VARS['DOCUMENT_ROOT'].'/compiled/');
$Smarty->config_dir=str_replace('//','/',$HTTP_SERVER_VARS['DOCUMENT_ROOT'].'/');

$Smarty->compile_check=true;
$Smarty->caching=true;
$Smarty->config_load(dirname($HTTP_SERVER_VARS['SCRIPT_NAME']).'/'.substr($HTTP_SERVER_VARS['SCRIPT_NAME'],strrpos($HTTP_SERVER_VARS['SCRIPT_NAME'],'/')+1,100)."-".$cur_lang.'.conf');
$Smarty->display('file:'.$HTTP_SERVER_VARS['DOCUMENT_ROOT'].'/'.basename($HTTP_SERVER_VARS['SCRIPT_NAME'],'.php').'.tpl');
echo(str_replace('//','/','file:'.$HTTP_SERVER_VARS['DOCUMENT_ROOT'].'/'.basename($HTTP_SERVER_VARS['SCRIPT_NAME'],'.php').'.tpl'));
?>
[/php:1:0f3207c303]

Template is shown, but under Windows caching is done to the root dir of drive C:, despite of $Smarty->caching_dir=str_replace('//','/',$HTTP_SERVER_VARS['DOCUMENT_ROOT'].'/cached/'); setting.

Under Linux/Unix Server, Smarty can't write to root dir, therefore caching doesn't work at all.

Please show me my error in Smarty config. I'm using Smarty 2.5.0 on Windows 98 (Apache) and Unix (Apache) at my ISP.
_________________
Things are changing,
But nothing changes,
And still there are changes
Back to top
View user's profile Send private message Send e-mail
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sat Nov 01, 2003 1:04 pm    Post subject: Reply with quote

it's called cache_dir not caching_dir.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat Nov 01, 2003 1:13 pm    Post subject: Reply with quote

Also, I don't see what good replacing '//' with '/' is in this example. Shouldn't it be '\\' ?
Back to top
View user's profile Send private message
FractalizeR
Smarty Rookie


Joined: 01 Nov 2003
Posts: 16

PostPosted: Sat Nov 01, 2003 1:49 pm    Post subject: Reply with quote

Thanks a lot, Sirs!
As I supposed, the problem was stupid and the solution is very easy. Thanks a lot again.

I am replacing '//' with '/' because I develop site under Windows and target platfom is Unix. Variable $HTTP_SERVER_VARS['DOCUMENT_ROOT'] on Windows doesn't end with '/', but on Unix it does. So, I add slash anyway and the replace '//' as it occur on Unix to '/'.

But may be '//' equals '/' on both platforms? Is '//' symbol treated as '/' in any situation relative to path to file or directory and I may not to take care of it?
_________________
Things are changing,
But nothing changes,
And still there are changes
Back to top
View user's profile Send private message Send e-mail
tk
Smarty Regular


Joined: 31 Oct 2003
Posts: 49
Location: London, UK

PostPosted: Sun Nov 02, 2003 1:31 am    Post subject: Reply with quote

Quote:
Code:
$Smarty->caching_dir=str_replace('//','/',$HTTP_SERVER_VARS['DOCUMENT_ROOT'].'/cached/')


Are all the str_replace() etc calls necessary? What about something like:

Code:
$Smarty->cache_dir = dirname(__FILE__) . '/cached/';


or for files not in the root dir:

Code:
$Smarty->cache_dir = dirname(__FILE__) . '/../cached/';


for example. Less code, less chance of error. I've yet to encounter a problem using this method both on windoze and *nix.


HTH.



Regards,

tk
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun Nov 02, 2003 2:32 am    Post subject: Reply with quote

FractalizeR wrote:

I am replacing '//' with '/' because I develop site under Windows and target platfom is Unix. Variable $HTTP_SERVER_VARS['DOCUMENT_ROOT'] on Windows doesn't end with '/', but on Unix it does. So, I add slash anyway and the replace '//' as it occur on Unix to '/'.

I think I too quickly read your code and misinterpreted why you were doing that replacement. It occurs to me that I have noticed that PHP groks paths with // as / on windows, though I can't confirm that at the moment as I always try to avoid those situations...which I take is what are doing too Wink

Cheers.
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