电脑技术学习

PHPCMS教程:定义字段功能在各模块的调用方法,以评论为例讲解

dn001

我给出一个phpcms2007自定义字段在各个模块的调用方法吧,而且给留言本或者其他模块加自定义字段也完全类似。会php编程的看起来应该很好理解,不会的只能照着做了。

下面以给评论模块加自定义字段功能为例进行讲解(请注意下文中提到的“上面和“下面,不要错位):

1、修改 ./comment/admin/menu.inc.php

$menu[$mod][] = array("模块配置","?mod=".$mod."&file=setting");


下加入一行

$menu[$mod][] = array("自定义字段","?mod=phpcms&file=field&action=manage&tablename=".$CONFIG['tablepre']."comment");


2、修改 ./comment/include/common.inc.php

include MOD_ROOT.'/include/global.func.php';


下加入2行

require_once PHPCMS_ROOT.'/include/field.class.php';
$field = new field($CONFIG['tablepre'].'comment');


3、修改 ./comment/post.php

$enabledkey = explode(",",$MOD['enabledkey']);


上面加入一行

$field->check_form();


if($passed == 1) update_comments($keyid, $itemid, 1);


上面加入2行

$cid = $db->insert_id();
$field->update("cid=$cid");


4、修改 ./comment/list_js.php

include template('comment', 'comment_submit');


上面加入一行

$fields = $field->get_form('$title:$input $tool $note <br/>');


5、修改 ./comment/index.php

include template($mod, 'index');


上面加入一行 $fields = $field->get_form('$title:$input $tool $note <br/>');

6、修改模板 ./templates/default/comment/comment_submit.html

<!--{if $MOD['enablecheckcode'] }-->验证码:


上面加入一行

{$fields}


7、修改模板 ./templates/default/comment/index.html

<!--{if $MOD['enablecheckcode'] }-->验证码:


上面加入一行

{$fields}


8、修改模板 ./templates/default/comment/tag_comment_list.html

<!--{loop $comments $comment}-->


下面适当地方加入类似

QQ:{$comment[my_qq]}


的代码,my_qq为自定义字段名

9、至此代码都修改完毕,请进后台点“功能模块,在左边导航找到“评论管理,然后点“自定义字段,进去加字段吧

如果有的模块需要实现按自定义字段搜索的可以参考
./module/article/search.inc.php 和搜索模板 ./templates/default/article/search.html

标签: