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

Upgrade 2.x -> 3.x helper

 
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 -> Smarty 3
View previous topic :: View next topic  
Author Message
mmerlone
Smarty Rookie


Joined: 03 Jan 2007
Posts: 5

PostPosted: Mon May 16, 2011 7:34 pm    Post subject: Upgrade 2.x -> 3.x helper Reply with quote

Hi all,

I am evaluating the upgrade from 2.x to 3.x. I read http://smarty-php.googlecode.com/svn/trunk/distribution/SMARTY2_BC_NOTES and was wondering if someone has made or is planning to make or know of any tool to help me find incompatibilities and code I should change to make it compatible with 3.x.

Looking for advices, thanks in advance.

Best regards.
_________________
Marcio Merlone
Back to top
View user's profile Send private message MSN Messenger
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon May 16, 2011 7:45 pm    Post subject: Reply with quote

3.1 has a better upgrade path, I'd hold out for that (coming in the following weeks) It has a separate class specifically for 2.0 BC.

Otherwise the README and BC_NOTES have the pertinent info for upgrading. Most certainly try this in a test area first.
Back to top
View user's profile Send private message Visit poster's website
Mimidog
Smarty n00b


Joined: 12 Aug 2011
Posts: 3

PostPosted: Fri Aug 12, 2011 1:51 pm    Post subject: smarty2 to 3 Reply with quote

I too am looking for some help with this subject please! I know parts of the code need to be changed but how much? and on what pages? All of the display pages or just some of the areas on each page what are we looking for? Please any suggestions would be great!
Back to top
View user's profile Send private message
olivierpons
Smarty Rookie


Joined: 13 Aug 2011
Posts: 13
Location: France

PostPosted: Sat Aug 13, 2011 9:10 am    Post subject: Reply with quote

Here are the problems I've encountered so far:
-----------------------------
- the template dir is not allowed to begin with "." or "../" anymore.
So you need to add this line:

Code:
$this->template = realpath($this->template);

-----------------------------
- we have a full multilanguage included closely with smarty, and a template function that calls the "traductor object". template functions were declared like this:
Code:
$this->smarty->register->templateFunction('trad', array($this,'smarty_trad'))


now the v3 version looks like (I've not tested it 100%):
Code:
$this->smarty->registerPlugin('function','trad', array($this,'smarty_trad'));

-----------------------------
- in all your templates, if your variables are not set, you'll get a warning:
Code:
Notice: Undefined index: code_postal in /xxx/smarty/compile/7f51dda2964466d9ce44bb3865674110e66ee097.file.index.htm.php on line 391

so you'll have to change all your template code from:
Code:
{if $tab_err.code_postal}

to
Code:
{if isset($tab_err.code_postal)}

-----------------------------


Last edited by olivierpons on Sat Aug 13, 2011 10:06 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Sat Aug 13, 2011 9:27 am    Post subject: Reply with quote

As much as I welcome the help offered, I do think you should check your statements before publishing them, olivierpons.

Registering plugins (functions, modifiers, …) is done (as the doc states):
Code:
$smarty->registerPlugin("function", "my_cool_function", "the_actual_php_function");


You should never access any internal attributes directly. $smarty->template_functions may work for you now - but what about tomorrow? internal functions are not part of the publicly documented API. Internal functions may be modified as needed. As they are internal, we don't really communicate those changes. Read: use the public API, everything else is prone-to-break-haxxory.

Regarding the note on undefined variables, yes it's true. Smarty3 does not automatically ignore any unset variable notices. But you can enable that behaviour quite easily:
Code:
$smarty->error_reporting = error_reporting() & ~E_NOTICE & ~E_WARNING;
The previous line sets the level of error reporting to simply ignore all notices and warnings (thus ignoring unset variable hints). Use at your own discretion. We'd urge you to clean your templates rather than throw a blanket of "please don't show me what I did wrong" over them.
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
olivierpons
Smarty Rookie


Joined: 13 Aug 2011
Posts: 13
Location: France

PostPosted: Sat Aug 13, 2011 10:09 am    Post subject: Reply with quote

You're right, I've modified my help according to what you said. Thank you.
Back to top
View user's profile Send private message Visit poster's website
dleffler
Smarty Rookie


Joined: 20 Sep 2011
Posts: 8

PostPosted: Tue Sep 20, 2011 3:18 pm    Post subject: Some additional considerations Reply with quote

(I'm using 3.0.9 & 3.1)
- $smarty->_tpl_vars is deprecated (without notice), but can be replaced by $smarty->getTemplatevars('name_of_var').
- v3 doesn't seem to like back-ticks and tends to throw exceptions when they are encountered. Since it's better at parsing, you can simply remove them in many cases
- v3.1 requires using the 'setter' (setPluginsDir) for changing the plugins_dir variable, but you MUST either include the system plugins folder in addition to a custom plugin folder path, or use the addPluginsDir() method
- moving from v2 to v3 to v3.1 (compatibility) can be as simple as adding the "BC" suffix such as changing the 'include" to reference SmartyBC.class.php and new SmartyBC();
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 -> Smarty 3 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