基本信息
源码名称:thinkphp 新闻系统源码下载
源码大小:28.75M
文件格式:.rar
开发语言:PHP
更新时间:2016-02-18
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
对于初步进入学习的更容易掌握

<?php
namespace Home\Controller;
use Think\Controller;
class FormController extends Controller{
	public function index(){
	//echo '1234';
	}
	//添加新闻
	public function insert(){
		$upload = upload_img();
		$info = $upload->upload();
		if(!$info){
			$this->error($upload->getError());
		}else{
			$form = D('news');
			
			if($_SERVER["REQUEST_METHOD"] == "POST"){
				
				$data['title'] = test_input(I('param.title'));
				$data['content'] = test_input(I('content'));
				$data['eauthor'] = test_input(I('eauthor'));
				$data['pic'] = $info['pic']['savepath'].$info['pic']['savename'];	

				$check_date = check_date(I('etime'));
				if($check_date){
					$data['etime'] = I('etime');
				}else{
					$data['etime'] = date("Y-m-d H:i:s",time());
				}
				
				//插入数据库
				if($form->create()){
					$result = $form->data($data)->add();
					if($result){
						$this->success('添加新闻成功,即将返回列表页面','../');
					}else{
						$this->error('添加新闻失败');
					}
				}else{
					$this->error($form->getError());
				}
				
			}else{
				$this->error('不是post提交的数据');
			}
			
		}
	}
	
	//读取新闻详情
	public function read($id=0){
		$form = M('news');
		$data = $form->find($id);
		if($data){
			$this->assign('data',$data);
		}else{
			$this->error();
		}
		
		$this->display();
		
	}
	
	
	//编辑新闻并更新到数据库
	public function edit($id=0){
		$form = M('news');
		$this->assign('vo',$form->find($id));
		$this->display();
	}
	
	public function update(){
		
		$upload = upload_img();
		$info = $upload->upload();
		if(!$info){
			$this->error($upload->getError());
		}else{
			$form = D('news');
			
			if($_SERVER["REQUEST_METHOD"] == "POST"){
				
				$data['id'] = $_POST['id'];
				$data['title'] = test_input($_POST['title']);
				$data['content'] = test_input($_POST['content']);
				$data['eauthor'] = test_input($_POST['eauthor']);
				$data['pic'] = $info['pic']['savepath'].$info['pic']['savename'];
				
				$check_date = check_date($_POST['etime']);
				if($check_date){
					$data['etime'] = $_POST['etime'];
				}else{
					$data['etime'] = date("Y-m-d H:i:s",time());
				}
				
				if($form->create()){
					$result = $form->data($data)->save();
					
					if($result){
						$this->success('修改新闻成功,即将跳转到详情页面',U('Form/read?id='.$data[id]));
					}else{
						$this->error('修改新闻信息失败,请重试');
					}
					
				}else{
					$this->error($form->getError());
				}
				
			}else{
				$this->error('不是post提交的数据');
			}
			
		}
		
	}
	
	//删除数据
	public function delete($id=0){
		$Form = M('news');
		$result = $Form->delete($id);
		if($result){
			$this->success('删除新闻成功!','/newskk_v3/');
		}else{
			$this->error('删除新闻信息失败!');
		}
	}
	
}
?>