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

[Smarty3] Settings when instantiating a Smarty object

 
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 -> Installation and Setup
View previous topic :: View next topic  
Author Message
JayBeeDe
Smarty n00b


Joined: 27 Oct 2016
Posts: 1

PostPosted: Thu Oct 27, 2016 10:26 am    Post subject: [Smarty3] Settings when instantiating a Smarty object Reply with quote

Hi,

I'm using Smarty 3 and it is working fine.
In my code I have to instantiate a lot of time some new smarty object.
For that I have to write each time:
[code] $smarty=new Smarty();
$smarty->force_compile=SMARTY_FORCE_COMPILE;
$smarty->template_dir=SMARTY_TEMPLATE;
$smarty->compile_dir=SMARTY_COMPILE;[/code]
How can I simplify this to:
[code]$smarty=new Smarty();[/code]
?
I have read the documentation, and seen a kind of configuration file but it seems not to be for that purpose. As smarty is a class, I don't want to change the content of the constructor.

Do you have an idea?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Oct 27, 2016 12:17 pm    Post subject: Reply with quote

http://php.net/OOP
Read that. The answer to your question is there, is clear and simple.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sat Oct 29, 2016 6:28 am    Post subject: Reply with quote

Note:

You should not assign directly to $smarty->template_dir and $smarty->compile_dir and other folder properties.
Use the setter functions. see
http://www.smarty.net/docs/en/api.set.compile.dir.tpl
http://www.smarty.net/docs/en/api.set.template.dir.tpl

Regarding your question

Code:

class MySmarty extends Smarty {
public $force_compile=SMARTY_FORCE_COMPILE;
protected $template_dir=SMARTY_TEMPLATE;
protected $compile_dir=SMARTY_COMPILE;
}

$smarty=new MySmarty();
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sun Oct 30, 2016 9:23 pm    Post subject: Reply with quote

Your code wouldn't work. Smarty::__construct() explicitly overwrites these values.
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 -> Installation and Setup 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