added support for extracting params to include_php

This commit is contained in:
mohrt
2003-02-05 14:56:27 +00:00
parent a253e9fba2
commit c0eabe7fbd
6 changed files with 45 additions and 7 deletions

2
NEWS
View File

@@ -1,3 +1,5 @@
- added support for passing params to include_php
(Tim Riley, Monte)
- added support for math operators in if statements (Monte)
- added support for $foo->bar[$x].blah syntax (Monte)

View File

@@ -1722,11 +1722,13 @@ class Smarty
* @param $_smarty_assign
* @param $_smarty_once
*/
function _smarty_include_php($_smarty_include_php_file, $_smarty_assign, $_smarty_once)
function _smarty_include_php($_smarty_include_php_file, $_smarty_assign, $_smarty_once, $_smarty_include_vars)
{
$this->_get_php_resource($_smarty_include_php_file, $_smarty_resource_type,
$_smarty_php_resource);
extract($_smarty_include_vars, EXTR_PREFIX_SAME, 'include_php_');
if (!empty($_smarty_assign)) {
ob_start();
if ($_smarty_resource_type == 'file') {

View File

@@ -858,7 +858,19 @@ class Smarty_Compiler extends Smarty {
$once_var = ( $attrs['once'] === false ) ? 'false' : 'true';
return "<?php \$this->_smarty_include_php($attrs[file], '$assign_var', $once_var); ?>";
foreach($attrs as $arg_name => $arg_value) {
if($arg_name != 'file' AND $arg_name != 'once' AND $arg_name != 'assign') {
if(is_bool($arg_value))
$arg_value = $arg_value ? 'true' : 'false';
$arg_list[] = "'$arg_name' => $arg_value";
}
}
$output =
"<?php \$this->_smarty_include_php($attrs[file], '$assign_var', $once_var, " .
"array(".implode(',', (array)$arg_list).")); ?>";
return $output;
}
@@ -1109,6 +1121,10 @@ class Smarty_Compiler extends Smarty {
case '~':
case ')':
case ',':
case '+':
case '-':
case '*':
case '/':
break;
case 'eq':

View File

@@ -167,14 +167,14 @@ $smarty = new Smarty;</screen>
</para>
<para>
Be sure you know the location of your web server document root. In our
example, the document root is "/web/www.domain.com/docs/".
example, the document root is "/web/www.mydomain.com/docs/".
</para>
<para>
The Smarty directories are defined in the class variables $template_dir,
$compile_dir, $config_dir and $cache_dir, which default to the values
"templates", "templates_c", "configs" and "cache" respectively. In our
example, we'll place all of these directories under
"/web/www.domain.com/smarty/guestbook/".
"/web/www.mydomain.com/smarty/guestbook/".
</para>
<note>
@@ -197,7 +197,7 @@ $smarty = new Smarty;</screen>
<para>
It is convenient to setup the web server so that "index.php" can be
identified as the default directory index, so if you access
"http://www.domain.com/guestbook/", the index.php script will be executed
"http://www.mydomain.com/guestbook/", the index.php script will be executed
without "index.php" in the URL. In Apache you can set this up by adding
"index.php" onto the end of your DirectoryIndex setting (separate each
entry with a space.)

View File

@@ -1722,11 +1722,13 @@ class Smarty
* @param $_smarty_assign
* @param $_smarty_once
*/
function _smarty_include_php($_smarty_include_php_file, $_smarty_assign, $_smarty_once)
function _smarty_include_php($_smarty_include_php_file, $_smarty_assign, $_smarty_once, $_smarty_include_vars)
{
$this->_get_php_resource($_smarty_include_php_file, $_smarty_resource_type,
$_smarty_php_resource);
extract($_smarty_include_vars, EXTR_PREFIX_SAME, 'include_php_');
if (!empty($_smarty_assign)) {
ob_start();
if ($_smarty_resource_type == 'file') {

View File

@@ -858,7 +858,19 @@ class Smarty_Compiler extends Smarty {
$once_var = ( $attrs['once'] === false ) ? 'false' : 'true';
return "<?php \$this->_smarty_include_php($attrs[file], '$assign_var', $once_var); ?>";
foreach($attrs as $arg_name => $arg_value) {
if($arg_name != 'file' AND $arg_name != 'once' AND $arg_name != 'assign') {
if(is_bool($arg_value))
$arg_value = $arg_value ? 'true' : 'false';
$arg_list[] = "'$arg_name' => $arg_value";
}
}
$output =
"<?php \$this->_smarty_include_php($attrs[file], '$assign_var', $once_var, " .
"array(".implode(',', (array)$arg_list).")); ?>";
return $output;
}
@@ -1109,6 +1121,10 @@ class Smarty_Compiler extends Smarty {
case '~':
case ')':
case ',':
case '+':
case '-':
case '*':
case '/':
break;
case 'eq':