View previous topic :: View next topic |
Author |
Message |
iop Smarty Rookie
Joined: 06 Dec 2010 Posts: 18
|
Posted: Mon Dec 06, 2010 7:34 pm Post subject: date (date_format) |
|
|
Hey
Yesterday I installed the latest (3.0.5) smarty version on my vserver and everything was fine, except the date/date_format.
Code: | {$entry.date}
//compiled file output
<?php echo $_smarty_tpl->getVariable('entry')->value['date'];?> | shows me the date I want, but if I chose a special format, there is nothing on the screen.
Code: | {$entry.date|date_format:'%a, %e %b %Y'}
//compiled file output
<?php echo date_format($_smarty_tpl->getVariable('entry')->value['date'],'%a, %e %b %Y');?> | does not work.
Before I worked in my local xampp installation under winxp and smarty version 2.6.26 and everything worked. Now I want to upload and host my site on a fresh installed vserver. Is this an smarty error or is possibly something wrong with my php installation..?!
Last edited by iop on Mon Dec 06, 2010 8:10 pm; edited 1 time in total |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Dec 06, 2010 7:52 pm Post subject: |
|
|
In your first code block:
{$entry.date} could never have been compiled to
<?php echo $_smarty_tpl->getVariable('data')->value[0]['date'];?>
Are u sure that your date is in $entry.date? |
|
Back to top |
|
iop Smarty Rookie
Joined: 06 Dec 2010 Posts: 18
|
Posted: Mon Dec 06, 2010 8:16 pm Post subject: |
|
|
Thanks for your answer U.Tews!
You are right, I posted the wrong code.. sorry. I edited the code in my first post, now it's right.
And right in this moment I saw, that I get a warning:
Code: | Warning: date_format() expects parameter 1 to be DateTime, string given in .../templates_c/....file.entry.tpl.php on line 32 |
Sorry that I posted before I checked that there are no warnings... ok, now I know whats going on, but before everything was fine under xampp and smarty.2.6. And I did not change the code, so why is there a warning now? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Dec 06, 2010 8:26 pm Post subject: |
|
|
My tests work but are showing a different compiled output, using smarty_modifier_date_format() in the compiled code. PHP 5.2 introduced its own date_format() function, and it looks like your compiled code is trying to use that. I'm using 5.2 in my tests though. But, that may be a clue to what is going on...
If you instantiate a vanilla Smarty object and load this template:
Code: | {$smarty.now|date_format} |
Does it work? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Dec 06, 2010 8:39 pm Post subject: |
|
|
Yes, your code compiled to use PHP function date_format
Smarty tries first to locate the plugin the plugins folder, only if that fails it tries to use the PHP function.
Looks like that your plugins_dir does not point the the right folder containing
modifer.date_format.php.
Note that you must delete compiled template after this has been fixed. |
|
Back to top |
|
iop Smarty Rookie
Joined: 06 Dec 2010 Posts: 18
|
Posted: Mon Dec 06, 2010 9:47 pm Post subject: |
|
|
Hey and thanks again for your replies!
@mohrt: I tried your template and got a formatted date. Following the compile output: Code: | <?php echo smarty_modifier_date_format(time());?> |
Also I tried $smarty->testInstall(); from the quick install guide and got this:
Code: | Smarty Installation test...
Testing template directory...
/var/www/.../smarty/templates is OK.
Testing compile directory...
/var/www/.../smarty/templates_c is OK.
Testing plugins directory...
/usr/local/lib/php/Smarty/plugins/ is OK.
Testing cache directory...
/var/www/.../smarty/cache is OK.
Testing configs directory...
/var/www/.../smarty/configs is OK.
Tests complete.
|
Everything seems to be fine. The plugins folder is at the place it has to be (usr/local/lib/php/Smarty). But my code still does not work.
Here is an extract from my tpl:
Code: | <div class="postHeader">{$entry.date} ODER {$entry.date|date_format:'%a, %e %b %Y'} in {$entry.city}</div> |
and here is the complied file: Code: | <div class="postHeader"><?php echo $_smarty_tpl->getVariable('entry')->value['date'];?>
ODER <?php echo date_format($_smarty_tpl->getVariable('entry')->value['date'],'%a, %e %b %Y');?>
in <?php echo $_smarty_tpl->getVariable('entry')->value['city'];?>
</div> |
Oh, when I put the template code from mohrt into my template I get the same problem.. so could there be a problem with my template?
Last edited by iop on Sun Jan 09, 2011 6:20 pm; edited 1 time in total |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Dec 06, 2010 9:58 pm Post subject: |
|
|
Does /usr/local/lib/php/Smarty/plugins/ contain file modifier.date_format.php ?
Does Smarty have read access to the files in /usr/local/lib/php/Smarty/plugins/ ?
Are you sure that you are using this plugins folder when using your template or did you modify plugins_dir from thze default setting? |
|
Back to top |
|
iop Smarty Rookie
Joined: 06 Dec 2010 Posts: 18
|
Posted: Mon Dec 06, 2010 10:05 pm Post subject: |
|
|
1. Yes, the plugins folder contains the file modifier.date_format.php
2. I think so, {$smarty.now|date_format} as a stand alone template outside my project work.
3. Code: | // define smarty lib directory
define('SMARTY_DIR', '/usr/local/lib/php/Smarty/'); | these lines are in my index.php which is called every time and i did not define a plugins_dir. |
|
Back to top |
|
iop Smarty Rookie
Joined: 06 Dec 2010 Posts: 18
|
Posted: Mon Dec 06, 2010 10:12 pm Post subject: |
|
|
me again..
in a test.php with this template {$smarty.now|date_format} i got following line in my compile file:
Code: | <?php if (!is_callable('smarty_modifier_date_format')) include '/usr/local/lib/php/Smarty/plugins/modifier.date_format.php';
?> |
in my project compiled files i do not get them.. why?! |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Dec 06, 2010 10:31 pm Post subject: |
|
|
Strange....
Are you sure that your templates got recompiled with the latest settings?
Is compile_check = true?
For testing try force_compile = true. |
|
Back to top |
|
iop Smarty Rookie
Joined: 06 Dec 2010 Posts: 18
|
Posted: Tue Dec 07, 2010 12:27 am Post subject: |
|
|
I think so, in between I deleted the old compile files just to verify if the templates are up to date..
here are some lines code.. perhaps it helps:
Code: |
// define our application directory
define('MYSITE_DIR', '/var/www/mysite/');
// define smarty lib directory
define('SMARTY_DIR', '/usr/local/lib/php/Smarty/'); |
Code: | // smarty configuration
class CMysiteSmarty extends Smarty
{
function CMysiteSmarty()
{
$this->template_dir = MYSITE_DIR . 'smarty/templates';
$this->compile_dir = MYSITE_DIR . 'smarty/templates_c';
$this->config_dir = MYSITE_DIR . 'smarty/configs';
$this->cache_dir = MYSITE_DIR . 'smarty/cache';
}
} |
Code: |
//instantiate the template object
$this->tpl = new CMysiteSmarty;
if($this->tpl->compile_check == true)
echo "compile_check == true";
else
echo "compile_check == false";
$this->tpl->force_compile=true; |
The output is compile_check == true.
Any ideas?
..oh, and thank you all for your fast help! |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Dec 07, 2010 12:41 am Post subject: |
|
|
Here we go.
If you extend the smarty class you must use PHP5 constructors.
Code: | class CMysiteSmarty extends Smarty
{
function __construct() {
parent::__construct();
$this->template_dir = MYSITE_DIR . 'smarty/templates';
$this->compile_dir = MYSITE_DIR . 'smarty/templates_c';
$this->config_dir = MYSITE_DIR . 'smarty/configs';
$this->cache_dir = MYSITE_DIR . 'smarty/cache';
}
} |
See also the SMARTY2_BC_NOTES. |
|
Back to top |
|
iop Smarty Rookie
Joined: 06 Dec 2010 Posts: 18
|
Posted: Tue Dec 07, 2010 7:15 pm Post subject: |
|
|
Thanks, I tried that but it did not work.
What else could be wrong? Again, creating a new test.php, new test.tpl everything seems to be right. But in my project it does not work. I already created new files for my php and tpl files and copied the old code into them... still the same problem. Hmmm.. I'll go through it again, perhaps I missed something.. |
|
Back to top |
|
iop Smarty Rookie
Joined: 06 Dec 2010 Posts: 18
|
Posted: Tue Dec 07, 2010 7:22 pm Post subject: |
|
|
It works! I missed another class in my project with an old constructor, changed it and now it works... thank you very, very much for your help! |
|
Back to top |
|
|