|
楼主 |
发表于 2015-9-28 17:35:58
|
显示全部楼层
这个use.php控制器--
<?php
class User extends CI_Controller {
function __construct() {
parent::__construct ();
$this->load->model ( 'usermodel' );
}
function user() {
$data ['news'] = $this->usermodel->art ();
$this->load->view ( 'admin/index.html', $data );
}
function contact() {
$this->load->view ( 'admin/contact.html' );
}
function short() {
$id = $this->uri->segment ( 4 );
$num=$this->uri->segment(5)+1;
$news ['onlynews'] = $this->usermodel->onlymessage ( $id );
if($news){
$this->update($id, $num);
$this->load->view ( 'admin/shortcodes', $news );
}
}
function showcon(){
//exit('sss');
$a_id=$this->uri->segment(4);
$avg=5;
if(!isset($_POST['c_comment'])||empty($_POST['c_comment'])||!isset($_POST['c_auth'])||empty($_POST['c_auth'])){
echo '{"success":false,"msg":"评论或用户名不能为空"}';
return;
}
$c_comment=$_POST['c_comment'];
$c_auth=$_POST['c_auth'];
$c_email=$_POST['c_email'];
$c_state='合格';
$c_crtime=date('y-m-d H:i:s',time());
$a_title=$_POST['a_title'];
$arr=array(
'c_comment'=>$c_comment,
'c_crtime'=>$c_crtime,
'c_auth'=>$c_auth,
'c_email'=>$c_email,
'c_state'=>$c_state,
'a_title'=>$a_title,
'a_id'=>$a_id
);
$re=$this->usermodel->comment($arr);
$num=$this->usermodel->re($a_id);
$allpages=ceil($num/$avg);
$arrRet=array('success'=>false);
if( $re===false ){
$arrRet['c_comment']='添加失败';
}else{
$arrRet['success']=true;
$arrRet['c_id']=$re;
$arrRet['c_comment']=$c_comment;
$arrRet['c_crtime']=$c_crtime;
$arrRet['c_email']=$c_email;
$arrRet['c_auth']=$c_auth;
$arrRet['num']=$num;
}
echo json_encode($arrRet);
}
function get_all(){
$a_id=$this->uri->segment(4);
$num=$this->usermodel->re($a_id);
$page=$_POST['page'];
$avg=$_POST['avg'];
$data=$this->usermodel->get_comment($a_id,$page,$avg);
$arrRet=array();
foreach($data as $d){
array_push($arrRet, array(
'c_id'=>$d->c_id,
'c_comment'=>$d->c_comment,
'c_auth'=>$d->c_auth,
'c_email'=>$d->c_email,
'c_crtime'=>$d->c_crtime,
'num'=>$num
));
}
echo json_encode($arrRet);
}
function aa(){
$a_id=$this->uri->segment(4);
$num=$this->usermodel->re($a_id);
return $num;
}
function update($id,$num){
$data=$this->usermodel->update($id,$num);
return $data;
}
}
?>
|
-
|