第八節視頻:javascript
CI框架學習-實例操做載入文章管理系統模板引入外部文件php
1、文章管理功能html
一、發表文章java
1)對數據庫添加一篇文章數據庫
a、在數據庫中創建一個表框架
登錄數據庫 -> use article; -> create table hd_article(aid int unsigned primary key auto_increment,title varchar(155) not null default ",content text,time int unsigned not null default 0,thumb varchar(70) not null default ",type tinyint(1) unsigned not null default 0,info varchar(155) not null default ",cid int unsigned not null default 0);編輯器
-> desc hd_article;post
2)數據庫操做,首先創建一個模型(全部數據庫的操做都在模型裏面)學習
在 models 裏面新建 article_model.phpthis
//models裏article_model.php 文章發表模型 <?php if (!defined("BASEPATH")) exit("No direct script access allowed")?>; /*文章管理模型*/ class Article_model extends CI_Model{ /*發表文章*/ public function add($data){ $this ->db ->insert("article",$data); } }
3)在controllers ->admin ->article.php裏
/*發表文章動做*/ public function send(){ //載入表單驗證類 $this ->load ->library("form_validation"); //執行驗證 $status = $this -> form_validation ->run("article"); if($status){ $this ->load ->model("article_model","art"); $data = array(
"title" =>$this ->input ->post("title"),
"type" =>$this ->input ->post("type"),
"cid" =>$this ->input ->post("cid"),
"thumb" =>$this ->input ->post("thumb"),
"info" =>$this ->input ->post("info"),
"content" =>$this ->input ->post("content"),
"time" =>time()
); $this ->art ->add($data);
success("admin/article/index","發表成功"); }else { $this ->load ->helper("form"); $this ->load ->view("admin/article.html"); } }
4)調用百度編輯器:ueditor
在views ->admin ->article.html 裏引用百度編輯器:
<script type = "text/javascript" src = "<?php echo base_url() ?>org/ueditor/ueditor.all.min.js"></script>
<script type = "text/javascript">
window.UEDITOR_HOME_URL = "<?php echo base_url() ?>org/ueditor/";
window.onload = function(){
window.UEDITOR_CONFIG.initialFrameWidth = 900;
window.UEDITOR_CONFIG.initialFrameHeight = 600;
UE.getEditor("content");
}
</script>
<script type = "text/javascript" src = "<?php echo base_url() ?>org/ueditor/ueditor.config.js"></script>