<?php
// 本类由系统自动生成,仅供测试用途
class ListAction extends Action {
public function index(){
//$name = 'sunzhiayn';
//$this->assign('name',$name);
//$this->assign('admin',$res);
$this->display();
}
public function article(){
$cons = M ('Content'); //内容表
$cons1 = M('Admin'); //会员表
$res = $cons->order('id')->select();
// echo $res[0]['title'];
$arr = array();
for($i=0;$i<count($res);$i++){
$where['q_id'] = $res[$i]['q_id'];
//echo $where['q_id'];
//find查出的是一个一维数组
$a[$i] = $cons1->where($where)->find();
if($a[$i]){
$res[$i]['username'] = $a[$i]['username'];
}else{
$res[$i]['username'] = '未知';
} }
//var_dump($a);
$this->assign('content',$res);
$this->display();
} public function up(){
echo '执行修改';
}
/* @sunzhiyan
* 包含多选的删除方法
*/
public function del(){
echo '执行删除';
$cons = M ('Content'); //内容表 if($_GET['action'] == del ){
// print_r($_POST['checkbox']);
$page = $_POST['checkbox'];
$where = 'id in('.implode(',',$page).')';
// $page = implode(",",$_POST['checkbox']);
//$cons->where($where)->delete();
}elseif($_GET['id']){
$where['id'] = $_GET['id'];
}
$bool = $cons->where($where)->delete();
if($bool){
$this->success('删除成功,正在跳转....', '__URL__/article');
}else{
$this->error('新增失败,请重新执行','__URL__/article');
}
//多选删除; */
$this->display();
} public function add() { echo '这里是添加文章';
$clean = array();
$clean['title'] = $_POST['tilte'];
$clean['type'] = $_POST['select'];
$clean['contents'] = $_POST['contents'];
$clean['img'] = $_FILES['photo1']['name'];
$clean['reg'] = date("Y-m-d",time());
$con = M('Content'); // 实例化User对象
if($_GET['action'] == add){
if($clean['img']){
//调用文件上传
$info = $this->upimg();
//print_r($info);
}
//接收文件上传后的编码文件,存入数据库中
$clean['img'] = $info[0]['savename'];
$res = $con->add($clean);
if($res){
// $this->success('添加成功,跳转中....','__URL__/article');
} else{
//$this->error('添加失败,跳转中....','__URL__/add');
}
} $this->display();
} public function upimg(){
import('ORG.Net.UploadFile');
$upload = new UploadFile();// 实例化上传类
$upload->maxSize = 3145728 ;// 设置附件上传大小
$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->savePath = './Public/Uploads/';// 设置附件上传目录
if(!$upload->upload()) {// 上传错误提示错误信息
$this->error($upload->getErrorMsg());
}else{// 上传成功 获取上传文件信息 $info = $upload->getUploadFileInfo();
//print_r($info);
} return $info;
} }