|
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 |
atomgiant Smarty n00b
Joined: 23 Apr 2003 Posts: 3
|
Posted: Wed Apr 23, 2003 12:48 pm Post subject: Smarty include_php issue |
|
|
I am having a problem that I believe is as a result of the way Smarty's include_php works.
I am using PEAR's HTML_QuickForm class to generate forms. Here is an outline of the structure:
myscript.php -> Smarty.display( myform.tpl ) -> php_include( myform.php )
Once the form is submitted via POST back to myscript.php, myform.php will process the data into a variable called $form. But I believe some data is being lost with the call to myform.tpl as the $form variable is not being created.
If I remove the call to myform.tpl and just include myform.php everything works fine.
I suspect that some variables that are available from a POST of a form are being lost in the middle step. I have tried printing out the _POST and _GET and GLOBALS from within myform.php... but everything seems to be there.
Can anyone think of some other alternatives... perhaps I am missing something obvious? Could scoping of variables change perhaps since $this is set to the $smarty object and perhaps the HTML_QuickForm object also refers to $this?
Thanks,
---Tom |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Apr 23, 2003 12:54 pm Post subject: |
|
|
i think the reason for your problem is, that stuff executed inside include_php is not in global context, but inside
a smarty-function.
that means: you have to declare every global variable you want to use as "global".
$GLOBALS, $_POST, $_GET_, $_REQUEST and $_SERVER are always global, so your variable may be reached via $GLOBALS['form']
but not via $form.
you would have to say "global $form;" in your included php
to make it accessible as "$form".
HTH
messju |
|
Back to top |
|
atomgiant Smarty n00b
Joined: 23 Apr 2003 Posts: 3
|
Posted: Wed Apr 23, 2003 1:50 pm Post subject: |
|
|
I have tried to declare it as 'global $form', but that does not work either. Could it be possible that since the include_php is executed inside a function that the scoping is not as expected? For example, if the following is the equivalent of how smarty implements an included php file:
Code: |
// smarty include function:
function include_php(...) {
include( 'some.inc.php' );
}
// some.inc.php:
$form = 'blah';
function doSomething() {
global $form;
...
}
|
Therefore, since the $form is created in the included some.inc.php, but it is actually created within the smarty include_php function, by saying 'global $form' in doSomething(), it won't work since the original scope of the $form var is local to smarty's include_php.
To make the above work, would I have to declare $form global from the start? As in:
global $form = 'blah'; OR $GLOBALS['form'] = 'blah';
Could you verify this logic?
Thanks,
---Tom |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Apr 23, 2003 2:11 pm Post subject: |
|
|
yepp. your elaboration is correct. |
|
Back to top |
|
atomgiant Smarty n00b
Joined: 23 Apr 2003 Posts: 3
|
Posted: Wed Apr 23, 2003 2:40 pm Post subject: |
|
|
Thanks for clearing that up. I appreciate it. |
|
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
|