在Smarty中声明变量并在PHP中用作参数传递

在Smarty中声明变量并在PHP中用作参数传递,php,smarty,Php,Smarty,我知道这可能看起来像是一个重复的问题,或者与类似的问题有点不同,但是,由于我一直在尝试论坛中提到的方法来解决问题,并且没有找到一个合适的解决方案,所以我提出了这个问题 问题 我将PHP与Smarty一起使用,并将MySQL结果分配给Smarty变量。我用来在输出中显示数据的。请参见下面的designation.php页面 <?php /** * Medical Application * * @package Medical Application */ require_once(

我知道这可能看起来像是一个重复的问题,或者与类似的问题有点不同,但是,由于我一直在尝试论坛中提到的方法来解决问题,并且没有找到一个合适的解决方案,所以我提出了这个问题

问题 我将PHP与Smarty一起使用,并将MySQL结果分配给Smarty变量。我用来在输出中显示数据的。请参见下面的designation.php页面

<?php
/**
 * Medical Application
 *
 * @package Medical Application
 */
require_once('header.php');

#to show department & Designation
$department = new User;
$smarty->assign('departmentList', $department->getDepartmentList());


$smarty->assign('designationList', $department->getDesignationList());

#to use template of given name
$smarty->display('designation.tpl');
有人能告诉我为什么会这样吗? 我已更改
$smarty=新的smarty
$smarty=新的SmartyBC也是。
有什么我错过的吗


提前感谢您的支持。

到目前为止,您找到解决方案了吗?我碰到了同样的问题。
{assign "title" "Department"}
{include file="header.tpl"}
{include file="partials/navbar.tpl"}

<div class="container mt-5">
    <div class="row">
        <div class="col-md-6">
            <div class="bg-white p-3 m-1 h-100">
                <h3>Add Designation</h3>
                {include file='partials/designationForm.tpl'}
                <span id='message'></span>
            </div>
        </div>
        <div class="col-md-6">
            <div class="bg-white p-3 m-1 h-100">
                <table  class="display responsive nowrap showTable" style="width:100%;">
                    <thead>
                        <tr>
                            <th>Department Name</th>
                            <th>Designation Name</th>
                            <th>Designation Short Name</th>
                            <th>Actions</th>
                        </tr>
                    </thead>

                    <tbody>
                {if is_array($designationList)}
                    {foreach from=$designationList key=k item=value}

                        {assign var="departmentid" value="{$value.department}"}

                        <tr>
                            <td>{$departmentid}
                                {php}
                                    $id = "$departmentid";
                                    $user = new User;
                                    $department = $user->getDepartmentList($id);
                                    print_r($department);
                                {/php}
                            </td>
                            <td>{$value.designation}</td>
                            <td>{$value.designation_sort}</td>
                            <td><a href="#" class='text-info' title="Edit"><i class="fa fa-pencil-square-o"></i></a> &ensp;<a href="#" class="text-danger" data-id="{$value.sno}" for="" of="" nonce="" title="Delete"><i class="fa fa-trash"></i></a> </td>
                        </tr>
                    {/foreach}
                  {/if}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{include file="footer.tpl"}
{assign var="departmentid" value="{$value.department}"}
 <td>{$departmentid}
                                {php}
                                    $id = "$departmentid";
                                    $user = new User;
                                    $department = $user->getDepartmentList($id);
                                    print_r($department);
                                {/php}
                            </td>
Undefined variable: departmentid