您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

smarty模板新手有关问题:提示在模板中发现未定义函数

2025/10/24 5:06:03发布17次查看
smarty模板新手问题:提示在模板中发现未定义函数
模板代码:
php code{include file ='header.tpl'}
{$tablename} 姓名:
测试:
{include file ='footer.tpl'}
index.php调用代码:
php code assign('title','测试标题'); $smarty -> assign('version',2011); $smarty -> assign('homepagelink','http://localhost/matance1.0/'); $smarty -> assign('tablename','标题'); if(isset($_post['ceshi2'])){ $smarty -> assign('wandoujia',$_post['ceshi2']); } $smarty -> display('index.tpl');?>
即在index.tpl模板上作一表单,action=index.php,index.php在加载模板时判断有木有传值,如果有,则给模板中$wandoujia函数传值
但运行后,总是提示:
notice: undefined index: wandoujia in d:\program files\wamp\www\mantance1.0\templatefile\templates\default\templates_c\da1ad7986fcfc741270ca7b7bdceba8d01b88c26.file.index.tpl.php on line 34
notice: trying to get property of non-object in d:\program files\wamp\www\mantance1.0\templatefile\templates\default\templates_c\da1ad7986fcfc741270ca7b7bdceba8d01b88c26.file.index.tpl.php on line 34
/>
求教
------解决方案--------------------
第一,这个不是未定义函数,只是为定义的index,
第二,看看此文件34行即可
d:\program files\wamp\www\mantance1.0\templatefile\templates\default\templates_c\da1ad7986fcfc741270ca7b7bdceba8d01b88c26.file.index.tpl.php
------解决方案--------------------
if(isset($_post['ceshi2'])){
$smarty -> assign('wandoujia',$_post['ceshi2']); 
}
没考虑wandoujia没有分配的情况,如果wandoujia没有值自然或报错。
------解决方案--------------------
把错误级别号改为5或者7,只报打错,notice错误可以直接忽略,对站点运行豪无影响,我们自己早期开发的php站点,因为当时写得不规范,至少有上百个notice级别错误,但是依然完美运行几年了。现在大家也懒得去修正。无所谓。
------解决方案--------------------
如果一定要纠正此notice级别的问题,你可以这么做:除了在php代码里判断post提交外:
 if(isset($_post['ceshi2'])){
$smarty -> assign('wandoujia',$_post['ceshi2']); 
}
还应该在模板里用smarty也判断是否有post提交。如果有就加入smarty变量wandoujia。注意这一段:
姓名:
试着改为:
姓名:
这里不一定是这样写,你最好直接看看post提交值的模板的2种输出情况,{$smarty.post.ceshi2}直接插入到一个标签里显示一下。看看有提交值跟没提交值适合{$smarty.post.ceshi2}的输出差别。这样就能判断是否需要加入$wandoujia变量了。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product