今天学习了CI的Model模型,总的来说Model完全就是用来给数据库打交道用了。
在models文件架建立blog_model.php用于给文章的数据增加,更新,查询的Model。

<?php class Blog_model extends Model {

public $post_title;
public $post_content;
public $post_date;

function __contrust(){
	parent::Model();
}

function insert_art(){
	$this->post_content = $this->input->post('content');
	$this->post_title   = $this->input->post('title');
	$this->post_date    = date('Y-m-d H:m:s');
	$this->db->insert('posts',$this);
}

function update_art($id){
	$this->post_content = $this->input->post('content');
	$this->post_title   = $this->input->post('title');
	$this->post_date    = date('Y-m-d H:m:s');
	$this->db->update('posts',$this,array('id'=>$id));
}

function get_ten_art() {
	$sql   = "select post_content,post_title,post_date from wp_posts limit 3";
	$query = $this->db->query($sql);
	return $query->result_array();
} } ?>

在控制器页面:

load->model('Blog_model','',TRUE);
	}

	function index(){
		$data['title'] = 'my web';
		$data['art']   = $this->Blog_model->get_ten_art();

		$this->load->view('blog_view',$data);
	}
	
	function insert(){
		$this->Blog_model->insert_art();
	}
	
	function update($id){
		$this->Blog_model->update_art($id);
	}
}
?>

Nginx 自动禁止爬虫IP采集

### 背景最近我们有一个公开服务提供给客户查询关键词的热度值,由于这个API做在官方网站上,自然没有用户登陆,也没有很高查询成本,所以设计上没有任何鉴权无法进行身份认定,于是就被一个爬虫开了超高并发请求,直接后端的AWS Tomcat CPU被用尽,导致无法响应。爬虫显然...… Continue reading

Redis原子性事务Lua应用

Published on June 28, 2020