phpcms前台的控制器

留言板测试玩的!

留言板测试玩的!

<?php
defined('IN_PHPCMS') or exit('No permission resource');


class index{
private $db;
function __construct(){
$siteid=isset($_GET['siteid'])?intval($_GET['siteid']):get_siteid();
define(SITEID,$siteid);
//加载模型
$this->db=pc_base::load_model(guestbook_model);
$this->tableName="v9_guestbook";
}

//默认的方法
public function init(){
$siteid=SITEID;
$setting=getcache('guestbook','commons');
$SEO=seo(SITEID,'',L('guestbook'),'','');

$array=$this->db->select();
/*echo "<pre>";
print_r($this->db);
echo "</pre>";
print_r($array);*/
include template('guestbook','index');
}




//留言方法
public function liuyan(){
$siteid=SITEID;
if(isset($_POST['lysubmi'])){
//验证字段
if($_POST['title']==""){
showmessage(L('title_noempty'),"?m=guestbook&c=index&a=liuyan&siteid=$siteid");
}
if($_POST['content']==''){
showmessage(L('content_noempty'),"?m=guestbook&c=index&a=liuyan&siteid=$siteid");
}
if($_POST['email']==''){
showmessage(L('email_onerror'),"?m=guestbook&c=index&a=liuyan&siteid=$siteid");
}
if($_POST['qq']==''){
showmessage(L('qq_onerror'),"?m=guestbook&c=index&a=liuyan&siteid=$siteid");
}


//安全过滤字段
$title=safe_replace($_POST['title']);
$content=safe_replace($_POST['content']);
$email=safe_replace($_POST['email']);
$qq=safe_replace($_POST['qq']);

$data=array('title'=>$title,'content'=>$content,'email'=>$emial,'qq'=>$qq);
$insert_id=$this->db->insert($data,$this->tableName,true);
if($insert_id>0){
echo "插入数据库成功!";
}

}else{
include template("guestbook","liuyan");

}

}
}
?>

标签: 数据库 加载