|
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 |
vesech Smarty Rookie
Joined: 21 Sep 2008 Posts: 10
|
Posted: Tue Dec 02, 2008 1:51 pm Post subject: Filename too long? |
|
|
Hello there,
I was trying to use some "text resources" as is outlined here http://blog.felho.hu/how-to-use-smarty-resources.html which I'm not 100% sure if smarty supports, but I figured I'd ask anyway.
This works great for templates within a certain character limit, the minute I go over this limit though fetch() is generating:
Code: |
Smarty::fetch(./templates_c/%%73^732^7320BE27%%text%3ATest+message+on+%7B%24therecord%7Creplace%3A%227%22%3A%229%22%7D%21%21%0D%0A%0D%0A%28%7B%24testno%7D%29+%7B%24surname%7D%2C+%7B%24forename%7D+%7B%24displayno%7D%0D%0A%0D%0A%7B%24thedetails%7Clower%7D%0D%0A%0D%0A%0D%0A%7B%24thecount%7D.php) [function.fetch]: failed to open stream: File name too long in /export/home/gaving/htdocs/includes/test/smarty/libs/Smarty.class.php on line 1256
|
Is there a solution to this aside from using another resource method? I'm trying to allow the use of text resources so I can test that templates are being set correctly with say, with PHPUnit. E.g.:
Code: |
public function testMessage() {
$message = <<<BODY
This is a text message with some variables {$test}.
This is a text message with some variables {$test2}.
This is a text message with some variables {$test3}.
This is a text message with some variables {$test4}.
This is a text message with some variables {$test5}.
This is a text message with some variables {$test6}.
BODY;
$this->notification->process(array('test' => 'test value'));
$this->assertEquals('This is a...', $this->notification->getRenderedBody());
}
|
Etc.
Cheers,
Gavin. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Dec 02, 2008 10:51 pm Post subject: |
|
|
Probplem is that in the text resource the template is passed in the template name which is used also to create the file names for the compiled template and cache files.
I see two possible work arounds:
1. Assign your string template to a smarty variable and use {eval} in your template.
2. Assign your string template to a global PHP variable, use anything short as template name and copy in smarty_resource_text_get_template the global PHP variable to $tpl_source. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Dec 03, 2008 12:05 am Post subject: |
|
|
By the way Smarty3, which is under development, has a standard "string" resource type and will not show this problem. |
|
Back to top |
|
vesech Smarty Rookie
Joined: 21 Sep 2008 Posts: 10
|
Posted: Fri Dec 05, 2008 8:04 am Post subject: |
|
|
U.Tews,
Thank you for your quick response and for manning these forums in general, you're a great help here.
I went with the first option and it has worked great, I should have thought of that one.
Cheers,
Ves. |
|
Back to top |
|
Brandon! Smarty n00b
Joined: 26 Feb 2009 Posts: 4
|
Posted: Thu Feb 26, 2009 10:32 pm Post subject: |
|
|
I ran into this exact problem using the exact resource. I didn't want to use the eval trick so I dug into the problem and traced it to where the filename is generated. How hard would it be to get a patch created? Here's my diff for Smarty.class.php:
Code: | 1749,1751d1748
< //the filename length has a limit, so a long resource name (auto_source) causes the template to fail
< $auto_source = substr($auto_source, 0, 100);
< |
The template blew up as soon as the resource/template name exceeded 137 characters. I truncated it to 100 just to be safe.
Another option that I just thought of that may help reduce collisions even more would be to hash $auto_source using md5.
Just food for thought.
EDIT:
Patch idea for a md5 hash:
Code: | 1749,1750c1749,1750
< // make source name safe for filename (the filename length has a limit, so a long template name (auto_source) causes it to fail)
< $_filename = (strlen($auto_source) > 100) ? urlencode(md5($auto_source)) : urlencode(basename($auto_source)); |
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Feb 26, 2009 11:03 pm Post subject: |
|
|
Just a bit of history, Smarty never used md5() for filename creation because of it's computation overhead. Since filenames are generated on every page load, it was decided to use a combination of urlencode() for file name recognition, and crc32() for hashing which is still plenty unique and 10x faster than md5() (at least it used to be, haven't benchmarked in some time.)
Smarty 3 alpha, I believe, is using md5() currently for filepath generation. We haven't done any exhaustive performance test on the code base yet, so it is yet to be determined if it will stay that way. If it is something negligible, it may stay.
Feel free to use md5() for your own purposes. Extend the class and make your own function for it. |
|
Back to top |
|
bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Fri Feb 27, 2009 7:32 pm Post subject: No need to extend the Smarty class |
|
|
I do not see there is a strong need to extend the Smarty class.
We rarely need the features of Smarty as our application logic.
In the function resources, $smarty object is instantly available with &$smarty parameter.
Modfiers may rearely or not at all need the $smarty object.
Same is the case for others.
To my way of programming, the guest book application in the official website is wrong, because, it does not clearly isolate the templating system. Rather, it mixes the programming/class files with the Smarty engine class files. (It made me confused, while I was learning the Smarty: Do I always have to extend the Smarty class? - Because, the sample application tells like that).
For example, if I am making a address book, I should write classes to use methods like, add_telephone(), edit_telephone(), and NOT like display('form.telephone.tpl').
If you do not extend the smarty class files, it becomes more clear about the differences between template engine, template files, application class files, and controllers. They all are different. Let the Smarty too remain unbound to your own applciation files. |
|
Back to top |
|
picraig Smarty n00b
Joined: 10 Sep 2009 Posts: 1
|
Posted: Thu Sep 10, 2009 5:08 pm Post subject: quick md5 extending code |
|
|
Code: |
class extSmarty extends Smarty
{
function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null)
{
return parent::_get_auto_filename($auto_base, ($auto_source !== null ? md5($auto_source) : null), $auto_id);
}
}
|
|
|
Back to top |
|
Ronald87 Smarty n00b
Joined: 17 Aug 2016 Posts: 1
|
Posted: Wed Aug 17, 2016 5:50 am Post subject: File name too Long? |
|
|
Give a try to Long Path Tool, it's great and easy to use. |
|
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
|
|