zoukankan      html  css  js  c++  java
  • 后盾网-CI框架实例教程-马振宇

    第八节视频:

        CI框架学习-实例操作载入文章管理系统模板引入外部文件

    一、文章管理功能

      1、发表文章

        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;

        2)数据库操作,首先建立一个模型(所有数据库的操作都在模型里面)

          在 models 里面新建 article_model.php

          

    //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>

  • 相关阅读:
    数据库 concat 与 ||
    mysql时间戳详解及运用
    mysql数据库事务的操作与理解
    数据分析实战——03丨Python基础语法:开始你的Python之旅
    数据分析实战——02丨学习数据挖掘的最佳路径是什么?
    数据分析实战——01丨数据分析全景图及修炼指南
    数据分析实战——开篇词 | 你为什么需要数据分析能力?
    从0开始学大数据学习笔记——37.如何对数据进行分类和预测?
    坚毅(GRIT)阅读笔记
    Make over monday – 每周动手实践的Tableau社区网站
  • 原文地址:https://www.cnblogs.com/chengshun/p/7637095.html
Copyright © 2011-2022 走看看