Php 尝试在smarty foreach中调用smarty插件(带参数)

Php 尝试在smarty foreach中调用smarty插件(带参数),php,codeigniter,plugins,recursion,smarty,Php,Codeigniter,Plugins,Recursion,Smarty,我正试图将一个个人插件嵌入我的smarty TPL文件中,但我无法让它工作 这是我的smarty插件: <?php function smarty_function_alticerik($params, &$smarty) { if (!function_exists('alticerik')) { if (!function_exists('get_instance')) return "Can't get CI instance"; $C

我正试图将一个个人插件嵌入我的smarty TPL文件中,但我无法让它工作

这是我的smarty插件:

<?php
function smarty_function_alticerik($params, &$smarty) {
    if (!function_exists('alticerik')) {
        if (!function_exists('get_instance')) return "Can't get CI instance";
        $CI= &get_instance();
    }

    return $CI->IceriklerMod->liste($params['where']);
}      
?>
{foreach item=alt from=alticerik|@alticerik(where="where ustid=$ustid")}
{$alt.id}
{/foreach}

我已经搜索并阅读了所有smarty帮助页面,但我仍然不知道如何才能使这些代码正常工作…

您的意思是
$CI=&get_instance()也许


什么不起作用?有错误吗?

您的意思是
$CI=&get_instance()也许


什么不起作用?有错误吗?

我相信您的问题是函数不会使用Smarty语法进行调用

你所做的是函数和修饰符的混合

修改器更改给定的输入-例如,降低管柱的套管

{$upperCaseWord|strtolower}
函数采用命名参数,通常做更多的工作,如创建下拉列表

{html_options options=$arrayOfOptions selected=$selectedValue}
在您的情况下,我猜您希望使用修饰符,因为您似乎正在尝试修改值。您仍然可以将选项传递给这些选项,但它们没有命名,而且很快就会变得相当混乱。但是,代码可能是:

{foreach item=alt from=$alticerik|@alticerik:"where ustid=$ustid"}
     {$alt.id}
{/foreach}
同时,您的实际功能如下所示:

<?php
function smarty_modifier_alticerik($input, $whereString) {
    // Here, $input is the same as your $alticerik variable
    // and $whereString is just the string that comes after the colon.
    if (!function_exists('alticerik')) {
        if (!function_exists('get_instance')) return "Can't get CI instance";
        $CI= &get_instance();
    }

    return $CI->IceriklerMod->liste($whereString);
}      
?>

我相信您的问题在于函数不会使用Smarty语法调用

你所做的是函数和修饰符的混合

修改器更改给定的输入-例如,降低管柱的套管

{$upperCaseWord|strtolower}
函数采用命名参数,通常做更多的工作,如创建下拉列表

{html_options options=$arrayOfOptions selected=$selectedValue}
在您的情况下,我猜您希望使用修饰符,因为您似乎正在尝试修改值。您仍然可以将选项传递给这些选项,但它们没有命名,而且很快就会变得相当混乱。但是,代码可能是:

{foreach item=alt from=$alticerik|@alticerik:"where ustid=$ustid"}
     {$alt.id}
{/foreach}
同时,您的实际功能如下所示:

<?php
function smarty_modifier_alticerik($input, $whereString) {
    // Here, $input is the same as your $alticerik variable
    // and $whereString is just the string that comes after the colon.
    if (!function_exists('alticerik')) {
        if (!function_exists('get_instance')) return "Can't get CI instance";
        $CI= &get_instance();
    }

    return $CI->IceriklerMod->liste($whereString);
}      
?>

关键是我不能在我的TPL文件中调用我的个人smarty插件(alticerik)。。。我需要调用“alticerik”函数并获取DB结果数组,然后在我的TPL文件中使用smarty的foreach。问题是我不能在我的TPL文件中调用我的个人smarty插件(它是alticerik)。。。我需要调用“alticerik”函数并获取DB结果数组,然后在我的TPL文件中使用smarty的foreach。请不要通过破坏您的帖子为其他人做更多工作。通过在Stack Exchange(SE)网络上发布,您已经在下授予SE分发内容的不可撤销权利(即,无论您未来的选择如何)。根据SE政策,分发非故意破坏版本。因此,任何故意破坏行为都将恢复原状。请参阅:。如果允许删除,在帖子下方左侧有一个“删除”按钮。您可能需要使用浏览器,而不是移动应用程序。请不要通过破坏您的帖子为他人做更多的工作。通过在Stack Exchange(SE)网络上发布,您已经在下授予SE分发内容的不可撤销权利(即,无论您未来的选择如何)。根据SE政策,分发非故意破坏版本。因此,任何故意破坏行为都将恢复原状。请参阅:。如果允许删除,在帖子下方左侧有一个“删除”按钮。您可能需要使用浏览器,而不是移动应用程序。