|
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 |
scuzzy Smarty Regular
Joined: 31 Aug 2003 Posts: 84
|
Posted: Thu May 10, 2018 1:06 am Post subject: Extending Smarty_Internal_Resource_File with my own behavior |
|
|
I know extending an "internal" class like "Smarty_Internal_Resource_File" is not ideal when "Smarty_Resource_Custom" exists.
However, I want to use 99% of the aspects of this class and change one minor thing by wrapping the parent method.
Code: | class MyFileResource extends Smarty_Internal_Resource_File
{
// literally nothing but the extends
}
$smarty->registerResource( 'myfile', new MyFileResource() );
$smarty->default_resource_type = 'myfile'; |
Now my problem is, if I try to have a relative template {include file="../foo.tpl"} I will get an error in the following code...
Code: | if ($_template->parent->source->type !== 'file' && $_template->parent->source->type !== 'extends' &&
!isset($_template->parent->_cache[ 'allow_relative_path' ])
) {
throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'");
} |
as $_template->parent->source->type is now "myfile" and not "file" even though my class extends Smarty_Internal_Resource_File
Anyone have suggestions on how to set allow_relative_path to be true without needing to duplicate function buildFilepath()?
Thank you.
Last edited by scuzzy on Thu May 10, 2018 1:18 am; edited 1 time in total |
|
Back to top |
|
scuzzy Smarty Regular
Joined: 31 Aug 2003 Posts: 84
|
Posted: Thu May 10, 2018 1:12 am Post subject: |
|
|
I have noticed that in an older version of smarty "allow_relative_path" is referenced multiple times, but now it only appears once?
Using: 3.1.32, Compared it to 3.1.27 (3.1.28 removed two of three references) |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri May 11, 2018 12:35 pm Post subject: |
|
|
This is why you do not extend internal classes. |
|
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
|