Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Upgrading from Smarty 2 to Smarty 3
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1127

PostPosted: Mon Jan 19, 2015 11:57 am    Post subject: Reply with quote

The PHP variables visibility scope does not intersect.
You shouldn't need to change your variables naming.
U.Tews was merely asking you to provide context.
Back to top
View user's profile Send private message
Chrissio
Smarty Rookie


Joined: 07 Oct 2014
Posts: 10

PostPosted: Mon Jan 19, 2015 3:28 pm    Post subject: Reply with quote

AnrDaemon wrote:
The PHP variables visibility scope does not intersect.
You shouldn't need to change your variables naming.
U.Tews was merely asking you to provide context.


Hi,

the hint that $tpl is a variable used in Smarty3 was the right one.

In the script i have to change from SMARTY2 (php4) to Smarty3 (php5.5) the variable $tpl was used about 120 times - after my first (wrong!) changes one part runs, but another part gives error messages like
Code:
"error in Smarty3/libs/Smarty.class.php..."
.

Now i changed all tu use $smarty... - the script runs but gives some notices like
Code:
Notice: Undefined index: sort in ... \compiled\3e8 ... 5a.file.xyz.tpl.php on line 82


With this notices i can work / live, because now i get correct php error messages like
Code:
 "function xy deprecated in file xy line xy"


The script i want to change was from another coder and for php4. It's always a challenge to change scripts of a strange programmer.

Thank you for all hints, if i have other questions i will make a post in associated boards.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1127

PostPosted: Mon Jan 19, 2015 3:36 pm    Post subject: Reply with quote

Your post didn't made any addition to the topic. You've been asked to show the context of your changes, but we are yet to see anything relevant to the request.
Back to top
View user's profile Send private message
Chrissio
Smarty Rookie


Joined: 07 Oct 2014
Posts: 10

PostPosted: Mon Jan 19, 2015 6:27 pm    Post subject: Reply with quote

AnrDaemon wrote:
Your post didn't made any addition to the topic. You've been asked to show the context of your changes, but we are yet to see anything relevant to the request.


Hi AnrDaemon,

normally there is no need to post the context of my changes, because:

I've made a mistake. Your posts dont give me a hint or help - the post from Uwe Tews was the solution:

U.Tews wrote:

$tpl is an internal variable used in Smarty3.


But only for you a code sample: Old code (Smarty2 / php4) in the application was like:

Code:

$tpl = some_function_somewhere();

...

$tpl->assign( "currency", _CURR );

$tpl->assign( "xy_version", _XY_VERSION );

$tpl->assign( "paypal", _PAYPAL );

...


    case "something_todo" :
        if ( !empty( $_POST['subject'] ) && !empty( $_POST['question'] ) ) {
            if ( do_it( $_POST['topic'], $_POST['subject'], $_POST['question'], "", "", 1 ) )
            {
                $tpl->assign( "message", _MESSAGE_REQUEST_SENT );
            } else {
                $tpl->assign( "error", true );
                $tpl->assign( "message", _ERROR_MAILING_ERROR );
                $tpl->assign( "question", $_POST['question'] );
                $tpl->assign( "subject", $_POST['subject'] );
            }
        } else {
            $tpl->assign( "error", true );
            $tpl->assign( "message", _ERROR_FIELDS_REQUIRED );
            $tpl->assign( "question", $_POST['question'] );
            $tpl->assign( "subject", $_POST['subject'] );
        }
        break;




First i've made the followed wrong changes:

Code:


/ * $tpl = some_function_somewhere(); */

// here ist the first (wrong!) change
$tpl = new Smarty;
// end of wrong change
...

$tpl->assign( "currency", _CURR );

$tpl->assign( "xy_version", _XY_VERSION );

$tpl->assign( "paypal", _PAYPAL );

...


    case "something_todo" :
        if ( !empty( $_POST['subject'] ) && !empty( $_POST['question'] ) ) {
            if ( sendemail( $_POST['topic'], $_POST['subject'], $_POST['question'], "", "", 1 ) )
            {
                $tpl->assign( "message", _MESSAGE_REQUEST_SENT );
            } else {
                $tpl->assign( "error", true );
                $tpl->assign( "message", _ERROR_MAILING_ERROR );
                $tpl->assign( "question", $_POST['question'] );
                $tpl->assign( "subject", $_POST['subject'] );
            }
        } else {
            $tpl->assign( "error", true );
            $tpl->assign( "message", _ERROR_FIELDS_REQUIRED );
            $tpl->assign( "question", $_POST['question'] );
            $tpl->assign( "subject", $_POST['subject'] );
        }
        break;


With the wrong changes application runs only in parts, but gives some other misleading error messages.

After the posting from Uwe Tews i've changed to:

Code:

// first change
$smarty = new Smarty;

...
// second change
$smarty->assign( "currency", _CURR );
// third change
$smarty->assign( "xy_version", _XY_VERSION );
// fourth change
$smarty->assign( "paypal", _PAYPAL );

...


    case "something_todo" :
        if ( !empty( $_POST['subject'] ) && !empty( $_POST['question'] ) ) {
            if ( sendemail( $_POST['topic'], $_POST['subject'], $_POST['question'], "", "", 1 ) )
            {
                $smarty->assign( "message", _MESSAGE_REQUEST_SENT );
            } else {
            // next changes
                $smarty->assign( "error", true );
                $smarty->assign( "message", _ERROR_MAILING_ERROR );
                $smarty->assign( "question", $_POST['question'] );
                $smarty->assign( "subject", $_POST['subject'] );
                // end
            }
        } else {
        // next changes
            $smarty->assign( "error", true );
            $smarty->assign( "message", _ERROR_FIELDS_REQUIRED );
            $smarty->assign( "question", $_POST['question'] );
            $smarty->assign( "subject", $_POST['subject'] );
            // end
        }
        break;



in all related parts of my application.

Result:

Smarty3 runs with my application in php5.6 .

application templates are shown, debug template too...

The application sends correct php error messages to fix it from php4 to php5.6.

No misleading error messages like "Fatal error: Call to a member function createTemplate() on null in C:\xampp\htdocs\Smarty3\libs\sysplugins\smarty_internal_templatebase.php on line 49"

It was nice to read your posts - but your posts was unusable. The post from Uwe Tews - here the part

U.Tews wrote:

$tpl is an internal variable used in Smarty3.


was the solution of all problems in my application after change to Smarty3.

Many thanks to Uwe Tews.

Actually i've only 1 notice like "Notice: Undefined offset: 1 in .../compiled/3e8d603f0ef90382418952262628476e6a685d5a.file.template_name.tpl.php on line 181", but before i cry for help i want to use my head or search engine to get a solution.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1127

PostPosted: Mon Jan 19, 2015 11:22 pm    Post subject: Reply with quote

The first part of your original code seems innocent. The latter... Was that a part of a custom template plugin?
Don't get me wrong, but I'm using the $tpl variable myself (it is in fact used in live project right now) and I've never encountered anything even close to your issues. Not to mention breakage of functionality.
Back to top
View user's profile Send private message
Chrissio
Smarty Rookie


Joined: 07 Oct 2014
Posts: 10

PostPosted: Tue Jan 20, 2015 11:13 am    Post subject: Reply with quote

AnrDaemon wrote:
Was that a part of a custom template plugin?


No!

The order of the changes (in knowing that the application runs without errors in php4!) was:

Adaptation of the deprecated messages from application:
- first all mysql-connect-related
- second all other like ereg..., strlen...
- no changes in simple notices, because in case you give an isset or @ to empty variables you get no information and no function.

Finally, there were only messages left from Smarty 2.6.8 - in other words exchange of Smarty Smarty 2.6.8 to 3.1.21 was necessary.

Before starting any changes i compared plugins - sysplugins folder from Smarty 2.6.8 with an original download. All seems like original.

Next step was creating a folder /Smarty3 / copy Smarty3, and change config of Smarty path from
define ('_SMARTY_PATH', _SERVER_ROOT . 'Smarty/libs/');
to
define ('_SMARTY_PATH', _SERVER_ROOT . 'Smarty3/libs/');
and changes in template and compile-paths...

After this i get the problems i have written in my first post...

And - the next problem i have is a simple: It is a buyed application; the copyright / license allowes me to change the code, but doesn't allowe me to post application code in a forum. Thats the reason why i cannot post something of the application code, and i hope you can accept it.

Thats all i can report, and it's my last post in this thread.

Thank you.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
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