开发者

How to use php code in tpl file in collabtive in smarty?

I need to use php code in tpl file in smarty. I used {php} echo "hello"; {/php} But I need to use a smarty variable in php code.

For example I need to use following variable {$myprojects[project].ID} in follo开发者_如何学JAVAwing php code in index.tpl file

{php}
    $qry = "select name from tasklist WHERE project = ".{/php} { {php}$myprojects[project].ID {/php} } {php}." ";
    echo $qry;
{/php}


You have a $this Smarty object in each template:

$this->get_template_vars('myprojects')


You have to write your code like this

{php}
    $var = $this->get_template_vars('myprojects');
    // if it is not an array you can use directly and if it is an array use as below.
        $qry = "select name from tasklist WHERE project = ".$var['key'];
        echo $qry;
    {/php}

for your knowledge and better coding help see below

it is better you can create a class and call an object of class in you php file and develop a function to get desired output.

    $objMyF = new my_functions();
    $smarty->assign('objMyF',$objMyF);

    //and in your tpl file you can call its functions by
    {$objMyF->function_name($var)}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜