ci框架学习整理
--
-- 表的结构 `yi_article`
--
CREATE TABLE IF NOT EXISTS `yi_article` (
`id` int(11) unsigned NOT NULL auto_increment,
`title` varchar(256) NOT NULL,
`content` mediumtext NOT NULL,
`add_man` varchar(20) NOT NULL,
`add_time` datetime NOT NULL,
`views` int(11) NOT NULL,
`tag` tinyint(4) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=21 ;
article.php
<?php
class Article extends CI_Controller{
public $tips;
function __construct(){
parent::__construct();
//加载我自己的类库
$this->load->library('myclass');
$this->load->database();
$this->load->helper('url');
$this->tips=array(
'required'=>' [%s] 是必须填写的!',
'is_unique'=>'此 [%s] 已经存在,请输入其它名称!',
'min_lenght'=>' [%s] 最小长度为 [%s]',
'max_length'=>'[%s] 最大长度为 [%s]'
);
}
function index(){
echo "这里是文章的首页";
echo "<br />";
//加载url辅助函数
$this->load->helper('url');
$addr=site_url('article/article_list');
echo "<a href='$addr'>查看文章</a>";
$addr=site_url('article/article_page');
echo "<a href='$addr'>查看分页</a>";
}
function article_list(){
echo "这里是文章列表";
//加载数据库模型
//$this->load->model('article_model');
//$this->article_model->index();
//读取所有的文章
$this->load->database();
echo "<br />";
$query=$this->db->where("id >",5)->select('id,title')->from('article')->order_by('id','desc')->limit(4)->get();
$info=$query->result_array();//当然你可以用result()
$this->myclass->p($info);
echo "第一条记录的标题:".$info[0]['title'];
echo "<br />";
echo "第二条记录的标题:".$info[1]['id'];
echo "<br />";
echo "表article中共有这么些记录:".$this->db->count_all('article');
echo "<br />";
echo "本次共查询出这么些条记录:".$query->num_rows();
}
function article_page($page=1){
///////////////////////////////////
$config=array();
//第一步查询出总记录数
$this->load->database();
$config['total_rows']=$this->db->select('*')->from('article')->count_all_results();
//每页记录数
$config['per_page']=5;
//基础url
$this->load->helper('url');
$config['base_url']=site_url('article/article_page');
//显示的链接数
$config['num_links']=100;
//在地址栏显示当前页码
$config['use_page_numbers']=true;
//定义首页
$config['first_link']='首页';
//定义末页
$config['last_link']='尾页';
//上一页
$config['prev_link']='上一页';
//下一页
$config['next_link']='下一页';
//把分页包起来
$config['full_tag_open']='<p>';
$config['full_tag_close']='</p>';
//第二步加载类库
$this->load->library('pagination');
$this->pagination->initialize($config);
echo $this->pagination->create_links();
/////////////////////////////////////
$page=$page?intval($page):1;
$start=($page-1)*$config['per_page'];
$query=$this->db->select('*')->from('article')->limit($config['per_page'],$start);
$info=$query->get()->result_array();
$this->myclass->p($info);
echo $this->pagination->create_links();
//echo base_url('abc/def');
}
protected function _page($total_rows,$per_page,$base_url){
///////////////////////////////////
$config=array();
//第一步查询出总记录数
//$this->load->database();////
$config['total_rows']=$total_rows;
//每页记录数
$config['per_page']=$per_page;
//基础url
$this->load->helper('url');////
$config['base_url']=site_url($base_url);
//显示的链接数
$config['num_links']=100;
//在地址栏显示当前页码
$config['use_page_numbers']=true;
//定义首页
$config['first_link']='首页';
//定义末页
$config['last_link']='尾页';
//上一页
$config['prev_link']='上一页';
//下一页
$config['next_link']='下一页';
//把分页包起来
$config['full_tag_open']='<p>';
$config['full_tag_close']='</p>';
//第二步加载类库
$this->load->library('pagination');
$this->pagination->initialize($config);
return $this->pagination->create_links();
/////////////////////////////////////
}
function page($page=1){
$config['per_page']=5;
$page=$page?intval($page):1;
$start=($page-1)*$config['per_page'];
$query=$this->db->select('*')->from('article')->limit($config['per_page'],$start);
$info=$query->get()->result_array();
return $info;
}
function article_add(){
$this->load->library('form_validation');
//开始设置验证规则
//set_message可以传一个一维数组
$chinesetips=$this->tips;
$this->form_validation->set_message($chinesetips);
/*
$this->form_validation->set_message('required', ' [%s] 是必须填写的!');
$this->form_validation->set_message('is_unique', '此 [%s] 已经存在,请输入其它名称!');
$this->form_validation->set_message('min_length', ' [%s] 最小长度为 [%s]');
$this->form_validation->set_message('max_length', ' [%s] 最大长度为 [%s]');
*/
$this->form_validation->set_rules('title','标题','trim|required|is_unique[article.title]|min_length[6]|max_length[12]');
$this->form_validation->set_rules('content','内容','required');
$this->form_validation->set_rules('tag','状态','required');
if($this->form_validation->run()==true){
echo "表单验证成功!";
print_r($this->input->post());
$data=$this->input->post();
unset($data['Submit']);
$data['add_time']=date('Y-m-d H:i:s');
$data['views']='0';
$st=$this->db->insert('article',$data);
if($st){
echo "数据插入成功!";
echo "新的id为:".$this->db->insert_id();
}
//echo get_magic_quotes_gpc();
}else{
echo "表单验证失败!";
echo "<br />";
echo validation_errors();
}
}
function article_add_viewer(){
$this->load->helper('url');
$this->load->view('article_add');
}
function article_links(){
$addr=site_url('article/article_mod_viewer/19');
echo "<a href='$addr'>修改19</a>";
}
function article_mod_viewer($id){
if($id==""){
echo "没有传递参数";
exit;
}
$this->load->helper('url');
//从数据库中查出来
$query=$this->db->select()->from('article')->where('id',$id)->get();
$info=$query->row_array();
print_r($info);
$this->load->view('article_mod',$info);
}
function abc($val){
$this->form_validation->set_message('abc','不行');
//p($val);
return true;
}
function article_mod(){
$this->load->library('form_validation');
//开始设置验证规则
//set_message可以传一个一维数组
$chinesetips=$this->tips;
$this->form_validation->set_message($chinesetips);
$this->form_validation->set_rules('title','标题','trim|required|min_length[6]|max_length[12]|callback_abc');
$this->form_validation->set_rules('content','内容','required');
$this->form_validation->set_rules('tag','状态','required');
if($this->form_validation->run()==true){
echo "表单验证成功!";
print_r($this->input->post());
$data=$this->input->post();
$id=$data['id'];
unset($data['id']);
unset($data['Submit']);
$data['add_time']=date('Y-m-d H:i:s');
$data['views']='0';
//p($data);
$st=$this->db->where('id',$id)->update('article',$data);
if($st){
echo "数据修改成功";
}else{
echo "数据修改失败";
}
}else{
echo "表单验证失败!";
echo "<br />";
echo validation_errors();
}
}
function article_del($id=''){
if($id==""){
//exit('请传id');
}
$id=array(17,18,19);
$this->db->where_in('id',$id)->delete('article');
$st=$this->db->affected_rows();
echo $st;
if($st){
echo "数据删除成功!";
}else{
echo "数据删除失败!";
}
}
}
?>
article_add.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="author" content="Www.XiaZaiBa.Com" />
<title>无标题 1</title>
</head>
<body>
<form name="form1" action="<?php echo site_url('article/article_add')?>" method="post">
标题:<input name="title" type="text" value="" /><br />
内容:<input name="content" type="text" value="" /><br />
添加人:<input name="add_man" type="text" value="" /><br />
添加时间:系统自动记录<br />
状态:<input name="tag" type="radio" value="1" />显示 <input name="tag" type="radio" value="0" />隐藏<br />
<input type="submit" name="Submit" value="提交" />
</form>
</body>
</html>
article_mod.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="author" content="Www.XiaZaiBa.Com" />
<title>无标题 1</title>
</head>
<body>
<form name="form1" action="<?php echo site_url('article/article_mod')?>" method="post">
标题:<input name="title" type="text" value="<?php echo $title;?>" /><br />
内容:<input name="content" type="text" value="<?php echo $content?>" /><br />
添加人:<input name="add_man" type="text" value="<?php echo $add_man;?>" /><br />
添加时间:系统自动记录<br />
状态:<input name="tag" type="radio" value="1" <?php if($tag==1)echo 'checked';?> />显示 <input name="tag" type="radio" value="0" <?php if($tag==0)echo 'checked';?> />隐藏<br />
<input type="submit" name="Submit" value="提交" />
<input type="hidden" value="<?php echo $id;?>" name="id" />
</form>
</body>
</html>
ci框架学习整理的更多相关文章
- 各种demo——CI框架学习
各种demo——CI框架学习 寒假学习一下CI框架,请各位多多指教! 一.CI的HelloWorld! 注意:CI禁止直接通过文件目录来访问控制器. ./application/controlle ...
- PHP,mysql,Linux,CI框架学习总结
PHP,mysql,CI框架学习总结 PHP标记 1.Xml风格<?php ?> 2.简短风格 <? ?> 需在php.ini中开启short_open_tag 3.asp风格 ...
- ci框架学习告一段落,总结一下
从网上弄了一张框架学习思维导图,从图中就可以看出ci用了设计模式中的MVC架构,使得用起来很简单方便 用了大概两个星期开发了一个<文章管理系统>觉得开发过程中学到了很多,挺不错的,而且在学 ...
- PHP CI框架学习
CI框架的URL辅助函数使用 URL 辅助函数文件包含一些在处理 URL 中很有用的函数 加载辅助函数 在使用CI框架的使用经常碰到跳转和路径方面的问题,site_url()和base_url()很容 ...
- CI框架学习笔记
打印SQL语句$this->dbRead->last_query(); 重映射方法正如上文所说,URI 的第二段通常决定控制器的哪个方法被调用.CodeIgniter 允许你使用 _rem ...
- CI框架学习——基本的用法(一)
一.必备知识 1.如何访问你的页面 我在控制器下面建立了admin文件夹,此文件夹下有login.php 文件,我们现在要访问这个文件 http://localhost/gradesystem/ind ...
- 【ci框架学习】控制器-视图
基础的东西就不写了,网上大把的教程,可以慢慢磨.这里说些要注意的要点. 1.所有控制器都必须间接或者直接继承控制器基类 CI_Controller. 2.文件命名尽量小写,因为ci使用的是pathin ...
- 【ci框架学习】环境搭建
系统 -- Ubuntu 14.0(虚拟机linux 实体机Windows) 目标环境 -- lnmp 附加内容: 1.目录共享(方便代码编写) 2.使用secure crt终端软件连接(便于操作,不 ...
- PHP CI框架学习笔记-分页实现程序
视图html <div id="body"> <form action="/index.php/search/index/" method= ...
随机推荐
- 线段树&&线段树的创建线段树的查询&&单节点更新&&区间更新
目录 线段树 什么是线段树? 线段树的创建 线段树的查询 单节点更新 区间更新 未完待续 线段树 实现问题:常用于求数组区间最小值 时间复杂度:(1).建树复杂度:nlogn.(2).线段树算法复杂度 ...
- 第2次作业——APP的案例分析
APP的案例分析 网易有道词典APP,使用这个软件有三年之久.唯独最爱的一点就是我每天都能听到不一样的英文歌看到创作歌手的来历,当然偶尔也会有其他国家的歌.起初使用这个软件的目的是用来查单词,每天积累 ...
- 学习日期时间控件 daterangepicker
aterangepicker 是一款日期时间控件,可选择“年,月,日,时,分,秒”,可选择单面板,也可选择双面板(起止时间). 单面板示例:daterangepicker 单面板 codepen 在线 ...
- web应用安全发展与介绍
安全与安全圈的认识 中国黑客的发展过程:1990年代初,部分人开始研究黑客技术 1997-1999年,黑客团队涌现,进入黄金时代, 21世纪初,黑客工具傻瓜化,门槛降低,黑客精神不在… 圈内熟知的安全 ...
- 【转】 android中的文件操作详解以及内部存储和外部存储
摘要 其实安卓文件的操作和Java在pc环境下的操作并无二致,之所以需要单独讲解是因为安卓系统提供了不同于pc的访问文件系统根路径的api,同时对一个应用的私有文件做了统一的管理.根据我的经验,初学者 ...
- Python学习之路 (五)爬虫(四)正则表示式爬去名言网
爬虫的四个主要步骤 明确目标 (要知道你准备在哪个范围或者网站去搜索) 爬 (将所有的网站的内容全部爬下来) 取 (去掉对我们没用处的数据) 处理数据(按照我们想要的方式存储和使用) 什么是正则表达式 ...
- crontab定时执行
一.crond简介 crond是linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务工具,并且会自动启动cro ...
- C#中控件Control的Paint事件和OnPaint虚函数的区别
句柄 : 句柄,是整个Windows编程的基础.一个句柄是指使用的一个唯一的整数值,即一个4字节(64位程序中为8字节)长的数值,来标识应用程序中的不同对象和同类对象中的不同的实例,诸如,一个窗口,按 ...
- 443 D. Teams Formation
http://codeforces.com/contest/879/problem/D This time the Berland Team Olympiad in Informatics is he ...
- 联想拯救者s15k重装w10系统教程
目的:1.自己平常健忘,且总是要重装系统,2.给看到此篇文章的人一点参考 ps:联想拯救者s15k系列,带有两个硬盘,一个是装系统的硬盘,大小约120G,一个是资料盘,大小约900G,系统重装在小硬盘 ...