我有一个php页面home.php
<?php
ob_start();
include_once("app_header.php");
$disableCreate = 'true';
//below code to show the home page template
$htmlrenderObj = Htmlrender::getObj();
$template_path = $htmlrenderObj->app_home_template_path."app_home.html";
$template = $htmlrenderObj->return_file_content($template_path);
ob_end_flush();
include_once("app_footer.php");
?>
在这个php页面中,我有一个php变量$disablecreate
,并且我正在使用操作前类HTMLrender提供将内容替换为html模板的常用方法。现在,基于$disablecreate
变量,我需要禁用Create超链接。
<tr>
<td valign="top" colspan="2">
<div id="menuId">
<ul>
<li><a href="view.php" id="tab-visited"> <span>View</span></a></li>
<li><a href="create.php" <?php echo $disableCreate; ?>><span>Create</span></a></li>
<li><a href="search.php?default=1"> <span>Search</span></a></li>
<li><a href="update.php"><span>Update</span></a></li>
<li><a href="about.php"><span>About</span></a></li>
<li><a href="help.php"><span>Help</span></a></li>
</ul>
</div>
</td>
</tr>
但我遇到了编译时错误。
Multiple annotations found at this line:
- Invalid character used in text string (<?php echo
$disableCreate; ?>>).
- Start tag (<a>) not closed.
如何禁用基于php变量的锚标记。
像这样更改html
<tr>
<td valign="top" colspan="2">
<div id="menuId">
<ul>
<li><a href="view.php" id="tab-visited"> <span>View</span></a></li>
<li><a <?php if(!$disableCreate) { echo "href='create.php'" }; ?> ><span>Create</span></a></li>
<li><a href="search.php?default=1"> <span>Search</span></a></li>
<li><a href="update.php"><span>Update</span></a></li>
<li><a href="about.php"><span>About</span></a></li>
<li><a href="help.php"><span>Help</span></a></li>
</ul>
</div>
</td>
</tr>
然后更改
$disableCreate = 'true';
至
$disableCreate = true;
通过这项工作,您可以使用以下条件检查$DisableCreate
值if(!$DisableCreate)
,并决定是否添加href