目錄
smarty模板新手有关问题:提示在模板中发现未定义函数
gt
lt
quot
smarty
smarty模板新手问题:提示在模板中发现未定义函数
模板代码:
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->{include file ='header.tpl'}
登入後複製
index.php调用代码:
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?phprequire_once dirname(__FILE__) . "\include\common.inc.php";require_once SR_TEMPLATE . "\TemplatesFunction.php"; $smarty = $GLOBALS['smarty']; $smarty -> 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变量了。
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前
By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
擊敗分裂小說需要多長時間?
3 週前
By DDD
R.E.P.O.保存文件位置:在哪里以及如何保護它?
3 週前
By DDD

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

Microsoft正在推出Windows 11 23H2版本到有Copilot的發布預覽頻道
