Fatal error: Cannot instantiate abstract class Action in G:\wamp\www\ThinkPHP\Common\common.php on line 277
程序代码
<?php
class IndexAction extends Action{
public function upLoad($fileName,$oldFile){
$imgSize = getimagesize($_FILES[$fileName]['tmp_name']);
import('ORG.Net.UploadFile');
$upload = new UploadFile();// 实例化上传类
$upload->maxSize = 3145728 ;// 设置附件上传大小
$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg','bmp');// 设置附件上传类型
$upload->savePath = IMG_UP_URL;// 设置附件上传目录
$upload->saveRule = md5(time());//文件名
$upload->thumb=true;
$upload->thumbMaxWidth=300;//缩小宽度
$upload->thumbMaxHeight=$upload->thumbMaxWidth*$imgSize[1]/$imgSize[0];//缩小高度
$upload->thumbPrefix="";//省略图前缀
if(!$upload->upload()) {// 上传错误提示错误信息
return false;
}else{// 上传成功 获取上传文件信息
$info = $upload->getUploadFileInfo();
unlink($upload->savePath.$oldFile);
return '/haobangda/Common/ads/'.$info[0]['savename'];
}
}
public function index(){
if(!empty($_SESSION['name']) && !empty($_SESSION['type'])){
$adminType = $_SESSION['type'];
switch($adminType){
case '1' : $userInfo['userType'] = '管理员';
$menus['menus'] = C('admin')+ $this->getAdMenu();
$addData['addData'] = 'inline-block';
break;
case '2' : $userInfo['userType'] = '网站SEO';
$addData['addData'] = 'none';
$menus['menus'] = C('seoer')+ $this->getAdMenu();
break;
case '3' : $userInfo['userType'] = '网站编辑';
$menus['menus'] = C('editer');
$addData['addData'] = 'inline-block';
break;
}
$userInfo['lastLogin'] = date('Y年m月d日 H:i:s',$_SESSION['last_login']);
$userInfo['time']= date('Y年m月d日 H:i:s');
$userInfo['admin'] = $_SESSION['name'];
$files = C('files');
$statistics['adminNum'] = BaseAdminAction::getAdminNun();
$model = M('HaobangdaUser');
$statistics['user'] = $model->count();
$lastDay = strtotime("-1 day");
$statistics['todayReg'] = $model->where('cys_create_time>'.$lastDay)->count();
$statistics['aritcle'] = HaobangdaWzAction::getArticleNum();
$model = M('HaobangdaMessage');
$statistics['message'] = $model->count();
$apache = array('win'=>php_uname(),'phpVersion'=>PHP_VERSION,
'host'=>$_SERVER["HTTP_HOST"],'language'=>$_SERVER['HTTP_ACCEPT_LANGUAGE'],
'sapi'=>php_sapi_name(),'upload'=>ini_get('upload_max_filesize'),
'postSize'=>ini_get('post_max_size'));
$tplVal = array($files, $menus,$userInfo,$apache,$statistics,$addData);
$this->assignSecArr($tplVal);
$this->display();
}else{
$this->display('login');
}
}
function verify(){
import('ORG.Util.Image');
//英文验证码
Image::buildImageVerify(4,2,gif,90,30,'verify');
//中文验证码
//Image::GBVerify();
}
public function userExit(){
$_SESSION = array();
header("location:/Lin9558/index.php/Index");
}
public function login(){
//验证码验证
/* if($_SESSION['verify'] != md5($_POST['verify'])){
$this->error('验证码不正确');
} */
$model = M('BaseAdmin');
$where['cys_admin'] = $_POST['name'];
$where['cys_password'] = md5($_POST['password']);
$record = $model->field('id,cys_admin,cys_last_login,cys_power,cys_locking')->where($where)->find();
if($record){
if($record['cys_locking']==1){
$this->display();
echo'<script>alert("该帐户已冻结! ");</script>';
}else{
$_SESSION['name'] = $record['cys_admin'];
$_SESSION['type'] = $record['cys_power'];
$_SESSION['last_login'] = $record['cys_last_login'];
$where['id'] = $record['id'];
$data['cys_last_login'] = time();
$model->where($where)->save($data);
header("location:/Lin9558/index.php/");
}
}else{
$this->display();
echo'<script>alert("用户名,或密码不正确! ");</script>';
}
}
//总控制器方法
public function controller(){
$menu = $_POST['menu'];
$handle = $_POST['handle'];
$yqlj = $_POST['yqlj'];
$actMol = $this->getTrueHandle($menu,$handle,$yqlj);
$action = A($actMol['handle']);
$model = D($actMol['handle']);
$yqlj = D($actMol['yqlj']);
$where = $actMol['where'];
if($_POST['sfield'] && $_POST['svalue']){
if($_POST['sfield']=='mid'){
$temp[$_POST['sfield']] = array('eq',$_POST['svalue']);
}else{
$temp[$_POST['sfield']] = array('like','%'.$_POST['svalue'].'%');
}
$temp = $model->parseFieldsMap($temp,0,1);
if(is_array($where)){
$where = $where + $temp;
}else{
$where = $temp;
}
$_SESSION['seach'] = $where;
}elseif($_SESSION['seach']){
$where = $_SESSION['seach'];
$field = $model->listField;
if(!array_intersect($where,$field)){
$_SESSION['seach'] = '';
}
}
echo $this->getDataList($action,$where,$menu,$handle,$yqlj);
}
//生成数据列表
public function getDatalist($action,$where,$menu,$handle,$yqlj){
import("ORG.Util.Page"); //导入分页类
$count = $action->getRecordsCount($where); //计算总数
$p = new Page( $count, 12);
$p->setConfig('header','条记录');
$p->setConfig('first','首页');
$p->setConfig('next','下一页');
$p->setConfig('prev',"上一页");
$p->setConfig('last','末页');
$page = $p->show();
$this->assign( "page", $page );
$config = $action->getModelConf();//取得模型配置
$listField = $config['listField'];
$order = $config['order'];
$records = $action->getRecords($where,$p->firstRow,$p->listRows,$order);
//print_r($records);exit;
$pageStr = '<div id="pageBar">'.$page.'</div>';
$tableId = 'dataTable';
$seach = '<div class="seachBox"><select id="seachSel" class="seachSel">';
foreach($config['seach'] as $key=>$val){
$seach .= '<option value="'.$key.'">'.$val.'</option>';
}
$seach .= '</select> <input id="seachVal" /> <a id="seach" href="javascript:">搜索</a></div>';
return $this->createList($records,$listField,$tableId,$menu,$handle).$pageStr.$seach;
}
//生成数据表格
public function createList($datas, $fields, $tableId,$menu,$handle,$yqlj){
$tabAttr = 'width="100%" align="center" border="0" cellpadding="5" cellspacing="1"bgcolor="#E2E2E2"';
$cont = '<table handle="'.$handle.'"menu="'.$menu.'" id="'.$tableId.'"'.$tabAttr.'><tr class="Tdata" align="center">';
foreach($fields as $val){
$cont .= '<td>'.$val.'</td>';
}
$cont .= '<td>操作</td></tr>';
foreach ($datas as $key => $record){
$cont .= '<tr id="row'.$key.'" height="30" bgcolor="#FFFFFF">';
foreach($fields as $key => $val){//字段
$cont .= '<td>'.$record[$key].'</td>';
}
$cont .= '<td width="100" align="center"><a class="edit"href="javascript:"id="'.$record["mid"].'">修改</a><a class="del" href="javascript:"id="'.$record["mid"].'">删除</a></td><tr/>';
}
$cont .= '</table>';
return $cont;
}
//编辑记录
public function edit(){
$menu = $_POST['menu'];
$handle = $_POST['handle'];
$yqlj = $_POST['yqlj'];
$id = $_POST['id'];
$actMol = $this->getTrueHandle($menu,$handle,$yqlj);
$action = A($actMol['handle']);
$model = D($actMol['handle']);
$handle = D($actMol['handle']);
$yqlj = D($actMol['yqlj']);
$where = $this->getEditWhere($menu,$handle,$yqlj);
$config = $action->getModelConf();
if($config['editField']){
$editField = array_merge($config['listField'],$config['editField']);
}else{
$editField = $config['listField'];
}
$typeInput = $config['typeInput'];
$inputVal = $action->getInputVal($where);
empty($inputVal)?'':$typeInput = array_merge_recursive($typeInput, $inputVal);
if($id){
if($actMol['handle'] == 'BaseContent'){
unset($typeInput['menuid'],$typeInput['keys']);
$typeInput['menuid']['input'] = 'hidden';
$typeInput['keys']['input'] = 'hidden';
}
$map['id'] = $id;
$records = $model->where($map)->select();
$records = $model->parseFieldsMap($records,1,2);
$data = $this->createInput($typeInput,$records);
}else{
$data = $this->createInput($typeInput);
}
$action = !-URL-!.'/save';
$formId = 'formSave';
echo $this->createEditBox($data,$editField,$formId,$handle,$menu,$action);
}
public function save(){//保存添加的新数据
$yqlj = $_POST['yqlj'];
$menu = $_POST['menu'];
$handle = $_POST['handle'];
$actMol = $this->getTrueHandle($menu,$handle,$yqlj);
$action = A($actMol['handle']);
$model = D($actMol['handle']);
//如果有文件上传
if($_FILES){
foreach($_FILES as $key=>$sec){
if($sec['error']==0){
$oldFile = basename($_POST[$key]);
$_POST[$key] = $this->upLoad($key,$oldFile);
}
}
}
$data = $model->create();
switch($menu){
case 'single':$data['cys_menuid'] = 0;
break;
case 'industry':
if($data['cys_menuid']=='0' || $data['cys_menuid']==''){
$data['cys_menuid']=$handle;
}
break;
}
if($data['id']!=''){
if($model->save($data))
echo 'update_succeed';
else
echo 'update_failed';//$this->error($model->getError());
}else{
if($model->add($data))
echo 'add_succeed';
else
echo 'add_failed';
}
}
public function del(){
if($_POST['handle'] && $_POST['id']){
$yqlj = $_POST['yqlj'];
$menu = $_POST['menu'];
$handle = $_POST['handle'];
$id = $_POST['id'];
$actMol = $this->getTrueHandle($menu,$handle,$yqlj);
$action = A($actMol['handle']);
$model = D($actMol['handle']);
$where = $actMol['where'];
if($model->delete($id)){
echo 'del_succeed';
}else{
echo 'del_failed';
}
}else{
echo'notable';
}
}
/*根据生成一组表单,用于更新或插入数据*/
/*$datas = array(
[0] => Array(
[id] => <input name="theMid[]" type="text" value="1" /><span>这是提示内容!</span>
[cys_action] => <select name="theName[]"><option value="1">操作1</option><option value="2">操作2</option></select><span>fsfsfsfs</span>
[cys_mid] => <textarea name="theModle[]">1</textarea><span>fsfsfsfs</span>
[myId] => 1
)
更多...
$fields = array(
'id'=> '操作ID',
'cys_action'=> '操作名',
'cys_mid'=>'操作所属模块ID'
);
$fields = array(
'id'=> '操作ID',
'action'=> '操作名',
'mid'=>'所属模块ID'
);
$saveAll //是否整体保存
)*/
public function createEditBox($datas, $fields, $formId, $handle,$menu,$action){
if(is_array($fields) && is_array($datas)){
$html .= '<form action="'.$action.'"enctype="multipart/form-data" method="post" id="'.$formId.'">';
$html .= '<table id="dataTable" align="center" cellspacing="2" menu="'.$menu.'" handle="'.$handle.'" class="editTable">';
foreach($datas as $dataSec){
foreach($fields as $fieldKey=>$fieldVal){
if(array_key_exists($fieldKey, $dataSec)){//只用配置中也出同的字段,才会显示
$html .= '<tr><td align="right">'.$fieldVal.':</td><td>'.$dataSec[$fieldKey].'</td></tr>';
}
}
$mid = $dataSec['myid'];
}
$html .= '<tr><td></td><td><input type="button" class="save"value="保存"><input type="button"class="reset" value="取消" /></td></table>';
$html .= '<input type="hidden"name="menu" value="'.$menu.'" /><input type="hidden"name="handle" value="'.$handle.'" /></form>';
}
return $html;
}
//二维数组生成模板变量
public function assignSecArr($tplVal = array()){
if(is_array($tplVal)){
foreach($tplVal as $key => $sec){
if(is_array($sec)){
$this->assign($sec);
}else{
$this->assign($tplVal);
}
}
}else{
return false;
}
}
/*根据配置文件生成 input框*/
/*
$types = array(
'id'=>array(
'input'=>'text',
'name'=>'userId[]',
'value'=>'0',
'msg'=>'可以不填写id,它会自动生成'
),
'name'=>array(
'input'=>'text',
'name'=>'user[]',
'value'=>'',
'msg'=>'请填写名称'
)
);
$datas = array(
array('id'=>'1','name'=>'tom'),
array('id'=>'2','name'=>'jim'),
);
*/
function createInput($types, $datas='', $mid=''){
if(is_array($types)){
if(is_array($datas)){$i = 0;
foreach($datas as $dataSec){
foreach($dataSec as $dataKey=>$dataVal){
if(array_key_exists($dataKey, $types)){
$inputName = ($types[$dataKey]['name']=='')?$dataKey:$types[$dataKey]['name'];//自动以字段名为input名
$inputValue = ($types[$dataKey]['value']=='')?$dataVal:$types[$dataKey]['value'];
switch($types[$dataKey]['input']){
case 'select':
$new[$i][$dataKey] = '<select style="width:305px;" name="'.$inputName.'">';
foreach($types[$dataKey]['value'] as $typKey=>$typeVal){
if($dataVal == $typKey){
$new[$i][$dataKey] .= '<option selected="selected" value="'.$typKey.'">'.$typeVal.'</option>';
}else{
$new[$i][$dataKey] .= '<option value="'.$typKey.'">'.$typeVal.'</option>';
}
}
$new[$i][$dataKey] .= '</select>';
break;
case 'textarea':
$new[$i][$dataKey] = '<textarea id="editer" rows="12" cols="80" class="xheditor" name="'.$inputName.'">'.$inputValue.'</textarea>';
break;
case 'file':
$new[$i][$dataKey] = '<input type="file" name="'.$inputName.'"/>';
$i++;
$new[$i][$dataKey] = '<input type="hidden" value="'.$inputValue.'" name="'.$inputName.'"/>';
break;
default:
$iptType = ($types[$dataKey]['input']=='')?'text':$types[$dataKey]['input'];
$new[$i][$dataKey] = '<input name="'.$inputName.'" type="'.$iptType.'" value="'.$inputValue.'" />';
break;
}
$new[$i][$dataKey] .= ($types[$dataKey]['msg']=='')?'':'<span>'.$types[$dataKey]['msg'].'</span>';
}
}
$new[$i]['myid'] = empty($mid)?$dataSec['mid'] : $mid;
$i++;
}
}else{
foreach($types as $typeKey=>$typeSec){
$inputName = ($typeSec['name']=='')?$typeKey:$typeSec['name'];//自动以字段名为input名
switch($typeSec['input']){
case 'select':
$select = '<select name="'.$inputName.'">';
foreach($typeSec['value'] as $valKey=>$valVal){
$select .= '<option value="'.$valKey.'">'.$valVal.'</option>';
}
$temp[$typeKey] = $select.'</select>';
break;
case 'textarea':$temp[$typeKey] = '<textarea rows="12" cols="80" class="xheditor" id="editer" name="'.$inputName.'">'.$typeSec['value'].'</textarea>';
break;
default:
$iptType = ($typeSec['input']=='')?'text':$typeSec['input'];
$temp[$typeKey] = '<input name="'.$inputName.'" type="'.$iptType.'" value="'.$typeSec['value'].'" />';
}
$temp[$typeKey] .= ($typeSec['msg']=='')?'':'<span>'.$typeSec['msg'].'</span>';
}
$new[0] = $temp;
}
}
return $new;
}
public function getTrueHandle($menu,$handle){
switch($menu){
case 'base': $trueHandle = 'Base'.$handle; $where = array();
break;
case 'other':$trueHandle = 'Haobangda'.$handle; $where = array();
break;
case 'single':$trueHandle = 'BaseContent';$where['fileid'] = $handle;
break;
case 'industry':$trueHandle = 'BaseContent'; $where['menuid'] = $handle;
break;
case 'info':$trueHandle = $handle; $where = array();
}
$data['handle'] = $trueHandle;
$data['where'] = $where;
return $data;
}
public function getEditWhere($menu,$handle){
switch($menu){
case 'base':$where = array();
break;
case 'single':$where['option']['cys_fileid'] = $handle;
break;
case 'industry':$where['option']['cys_fileid'] = '2';$where['content']['menuid'] = $handle;
break;
case 'info':$where = array();
}
return $where;
}
public function getAdMenu(){
$model = D('BaseFiles');
$where['id'] = array('not in','2,13,7,14');
$records = $model->field('id,cys_desc')->where($where)->select();
$temp[0] = 'single';
foreach($records as $sec){
$temp[$sec['id']] = $sec['cys_desc'];
}
$menus['单页面管理'] = $temp;
$model = D('BaseMenu');
unset($where,$temp);
$where['cys_keys'] = 'daohang';
$where['cys_index'] = array('not in','1,27');
$records = $model->field('cys_index,cys_menu_name')->where($where)->select();
$temp[0] = 'industry';
foreach($records as $sec){
$temp[$sec['cys_index']] = $sec['cys_menu_name'];
}
$menus['行业页面管理'] = $temp;
return $menus;
}
public function editupLoad(){
header('Content-Type: text/html; charset=UTF-8');
$inputName='filedata';//表单文件域name
$attachDir=COMMON_PATH;//上传文件保存路径,结尾不要带/
$dirType=1;//1:按天存入目录 2:按月存入目录 3:按扩展名存目录 建议使用按天存
$maxAttachSize=2097152;//最大上传大小,默认是2M
$upExt='txt,rar,zip,jpg,jpeg,gif,png,swf,wmv,avi,wma,mp3,mid';//上传扩展名
$msgType=2;//返回上传参数的格式:1,只返回url,2,返回参数数组
$immediate=isset($_GET['immediate'])?$_GET['immediate']:0;//立即上传模式,仅为演示用
ini_set('date.timezone','Asia/Shanghai');//时区
print_r($_POST);
$err = "";
$msg = "''";
$tempPath=$attachDir.'/'.date("YmdHis").mt_rand(10000,99999).'.tmp';
$localName='';
if(isset($_SERVER['HTTP_CONTENT_DISPOSITION'])&&preg_match('/attachment;\s+name="(.+?)";\s+filename="(.+?)"/i',$_SERVER['HTTP_CONTENT_DISPOSITION'],$info)){//HTML5上传
file_put_contents($tempPath,file_get_contents("php://input"));
$localName=urldecode($info[2]);
}
else{//标准表单式上传
$upfile=@$_FILES[$inputName];
if(!isset($upfile))$err='文件域的name错误';
elseif(!empty($upfile['error'])){
switch($upfile['error'])
{
case '1':
$err = '文件大小超过了php.ini定义的upload_max_filesize值';
break;
case '2':
$err = '文件大小超过了HTML定义的MAX_FILE_SIZE值';
break;
case '3':
$err = '文件上传不完全';
break;
case '4':
$err = '无文件上传';
break;
case '6':
$err = '缺少临时文件夹';
break;
case '7':
$err = '写文件失败';
break;
case '8':
$err = '上传被其它扩展中断';
break;
case '999':
default:
$err = '无有效错误代码';
}
}
elseif(empty($upfile['tmp_name']) || $upfile['tmp_name'] == 'none')$err = '无文件上传';
else{
move_uploaded_file($upfile['tmp_name'],$tempPath);
$localName=$upfile['name'];
}
}
if($err==''){
$fileInfo=pathinfo($localName);
$extension=$fileInfo['extension'];
if(preg_match('/^('.str_replace(',','|',$upExt).')$/i',$extension))
{
$bytes=filesize($tempPath);
if($bytes > $maxAttachSize)$err='请不要上传大小超过'.$this->formatBytes($maxAttachSize).'的文件';
else
{
switch($dirType)
{
case 1: $attachSubDir = 'day_'.date('ymd'); break;
case 2: $attachSubDir = 'month_'.date('ym'); break;
case 3: $attachSubDir = 'ext_'.$extension; break;
}
$attachDir = $attachDir.'/'.$attachSubDir;
if(!is_dir($attachDir))
{
@mkdir($attachDir, 0777);
@fclose(fopen($attachDir.'/index.htm', 'w'));
}
PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000);
$newFilename=date("YmdHis").mt_rand(1000,9999).'.'.$extension;
$targetPath = $attachDir.'/'.$newFilename;
rename($tempPath,$targetPath);
@chmod($targetPath,0755);
$targetPath=$this->jsonString($targetPath);
if($immediate=='1')$targetPath='!'.$targetPath;
if($msgType==1)$msg="'$targetPath'";
else $msg="{'url':'".$targetPath."','localname':'".$this->jsonString($localName)."','id':'1'}";//id参数固定不变,仅供演示,实际项目中可以是数据库ID
}
}
else $err='上传文件扩展名必需为:'.$upExt;
@unlink($tempPath);
}
echo "{'err':'".$this->jsonString($err)."','msg':".$msg."}";
}
function jsonString($str)
{
return preg_replace("/([\\\\\/'])/",'\\\$1',$str);
}
function formatBytes($bytes) {
if($bytes >= 1073741824) {
$bytes = round($bytes / 1073741824 * 100) / 100 . 'GB';
} elseif($bytes >= 1048576) {
$bytes = round($bytes / 1048576 * 100) / 100 . 'MB';
} elseif($bytes >= 1024) {
$bytes = round($bytes / 1024 * 100) / 100 . 'KB';
} else {
$bytes = $bytes . 'Bytes';
}
return $bytes;
}
function getTypeAds(){
$where['cys_fileid'] = $_POST['fieldId'];
$options = BaseOptionAction::getOptions($where);
foreach($options as $key=>$val){
$cont .= '<option value="'.$key.'">'.$val.'</option>';
}
echo $cont;
}
}代码比较多 原因是 我也不知道那里有错~~~ 最佳答案