Duke2018-05-20 09:23:31
<?php
namespace Admin\Controller;
use Think\Controller;
class ArticleController extends Controller {
public function lst( ){
//實例化
$article=D('ArticleView');
$count= $article->count();//# $count= $article->count();// 查詢滿足要求的總記錄數
$Page= new \Think\Page($count,5);// 實例化分頁類別傳入總記錄數和每頁顯示的記錄數(25)
$show= $Page->show();// 分頁顯示輸出
$list = $article->order('id desc')->limit($Page-> ;firstRow.','.$Page->listRows)->select();
$this->assign('list',$list);// 賦值資料集
$this->assign('page',$show);// 賦值分頁輸出
$this->display();
}
public function add(){
## //實例化
$article=D('article');
# if(IS_POST){
oST){
$date['title']=I('title');
$date['content']=I('content');
# $date['desc']= I('desc');
$date['cateid']=I('cateid');
if($_FILES['pic']['tmp_name']!= ''){
$upload = new \Think\Upload();// 實例化上傳類別
## $upload->maxSize=314578 ;
# $upload->exts =array('jpg', 'gif', 'png', 'jpeg');// 設定附件上傳類型
1 Path ./'; // 設定附件上傳根目錄
$upload->savePath ='/Public/Uploads/'; // 設定附件上傳(子)目錄
// 上傳 上傳 單一檔案
$info = $upload->uploadOne($_FILES['pic']);
if(!$info) {/# if(!$info) {/# 中錯誤提示訊息』/
## $this->error($upload->getError());
}1//
}1//
ate['pic'] =$info['savepath'].$info['savename'];
}
}else{
## }else{
## ##
if($article->create($date)){
if($article->add()){
o# 1 ,U('lst'));
}else{
$this->error('文章中加入失敗!');##
# # # }else{
## $this->error($article->getError());
# camp
# #.
$cateres=D('cates')->select();
$this->assign('cateres',$cateres);
# $this->display( );
}
## public function edit(){
//實例化
$article=D ('文章');
# $article=D ('文章');
# $article=D ('文章');
# $article=D ('文章');
# if(IS_POST){
$date['title']=I('title');
$date['content' ]=I(
## $date['content' ]=I(
## $date['content' ]=I(
## $date['content' ]=I(
##);
$date['desc']=I('desc');
$date['cateid']=I('cateid') ;# $_FILES['pic']['tmp_name']!=''){
$upload = new \Think\Upload();// 實例化上傳類別
# up $ >maxSize=3145728 ;//設定附件上傳大小
$upload->exts =array('jpg', 'gif', 'png', 'jpeg ');// 設定附件上傳類型
# $upload->rootPath= './'; // 設定附件上傳根目錄
$upload->savePath ='/Public/Uploads/'; // 設定附件上傳(子)目錄
// 上傳單一檔案
$info = $upload->uploadOne($_FILES['pic']);
#]);
# if(!$info) {// 上傳錯誤提示錯誤訊息
$this->error($upload->getError());
# o 上傳成功 }
# }
if($article->create($date)){
if($article-& 文章成功',U('lst'));
}else{
$this-
}else{
$this->error($article->getError());
#努## }
$articler=$article->find(I('id'));
$this->assign('articler'## $this->assign('articler',$articler);
## $cateres=D('cate')->select();
$this->assign('cateres',$cateres);
## >display();
}
# public function del(){
//實例化
$article=D('article');
if($article->delete(I('id'))){
$this->success('刪除文章##卷成功!
## }
public function sort(){
//var_dump($_POST); //打一排
//var_dump($_POST); //打成一列
); //分行打現來
$article=D('article');
## foreach ($_POST as $id => $sort) {
## // code...
$article->where(array('id'=>$id))->setField('sort',$sort);
## }
$this->success('排序更新成功! ',U('lst'));
}
}
回覆
0