zoukankan      html  css  js  c++  java
  • CI框架下部分简单的后台管理代码

    1.control层:

    GuanliCon层次

    代码如下:

    <?php
    defined('BASEPATH') OR exit('No direct script access allowed');

    class GuanliCon extends CI_Controller{
    public function __construct(){
    parent::__construct();
    $this->load->model('GuanliMo');
    $this->load->helper('url_helper');
    }
    public function view(){

    $this->load->view('administer-yonghuguanli');
    }
    //数据库中读取学生信息
    public function Show(){
    $data['item']=$this->GuanliMo->Yonghu();
    $this->load->view('administer-yonghuguanli',$data);
    }

    public function News()
    {
    $data['activity']=$this->GuanliMo->News();
    //var_dump($data['activity']);
    $this->load->view('index',$data);
    }
    public function get_Id($table,$id)
    {
    if($table=='activity')
    {
    $data['count_item'] = $this->GuanliMo->get_one_activity($id);
    $this->load->view('news1',$data);
    }
    }


    //数据库中读取试题
    public function Shows(){
    $data['data']=$this->GuanliMo->Shiti();
    $this->load->view('administer-shitiguanli',$data);
    }
    //关键字搜索试题
    public function SearchShiti(){
    $num=$this->input->post('keywords');
    $data['data']=$this->GuanliMo->SearchShiti($num);
    $this->load->view('administer-shitiguanli',$data);
    }
    //数据库中读取答案
    public function Answer(){
    $data['answer']=$this->GuanliMo->Answer();
    $this->load->view('answer',$data);
    }
    //关键字搜索答案
    public function SearchAnswer(){
    $num=$this->input->post('keywords');
    $data['answer']=$this->GuanliMo->SearchAnswer($num);
    $this->load->view('answer',$data);
    }

    //删除学生信息
    public function ShanchuStudent($userID)
    {
    $no=$this->GuanliMo->ShanchuStudent($userID);
    $data['item']=$this->GuanliMo->Yonghu();
    //var_dump($data['item']);
    $this->load->view('shanchuyonghu',$data);
    }

    //删除学生信息
    public function ShanchuIntent()
    {
    $data['item']=$this->GuanliMo->Yonghu();
    $this->load->view('shanchuyonghu',$data);
    }

    //删除试题
    public function ShanchuShiti($num){
    $no=$this->GuanliMo->ShanchuShiti($num);
    $data['data']=$this->GuanliMo->Shiti();
    $this->load->view('administer-shitiguanli',$data);
    }

    //删除答案
    public function ShanchuAnswer($num){
    $no=$this->GuanliMo->ShanchuAnswer($num);
    $data['answer']=$this->GuanliMo->Answer();
    $this->load->view('answer',$data);
    }
    //数据库中读取答案
    public function ShanchuIntents(){
    $data['answer']=$this->GuanliMo->Answer();
    $this->load->view('answer',$data);
    }

     


    //修改学生信息
    public function Xiugai(){
    $userName=$this->input->post('userName');
    $usersex=$this->input->post('usersex');
    $userID=$this->input->post('userID');
    $userPassword=$this->input->post('userPassword');
    $email=$this->input->post('email');

    $data['item']=$this->GuanliMo->Xiugai($userName,$usersex,$userID,$userPassword,$email);

    $this->load->view('administer-yonghuguanli',$data);

    }
    //新增学生信息
    public function XinYonghu(){
    $this->load->view('xinzengrenyuan');
    }
    public function Xinzeng()
    {
    $userName=$this->input->post('userName');

    $usersex=$this->input->post('usersex');
    $userID=$this->input->post('userID');
    $userPassword=$this->input->post('userPassword');
    $email=$this->input->post('email');
    $worktype=$this->input->post('worktype');
    $adddata=$this->GuanliMo->Xinzeng($userName,$usersex,$userID,$userPassword,$email,$worktype);
    $this->load->view('xinzengrenyuan',$adddata);
    }
    //新增试题
    public function XinShiti(){
    $this->load->view('xinzengshiti');
    }
    public function XinzengShiti()
    {
    $num=$this->input->post('num');

    $body=$this->input->post('body');
    $type=$this->input->post('type');
    $adddata=$this->GuanliMo->XinzengShiti($num,$body,$type);
    $this->load->view('xinzengshiti',$adddata);
    }
    //新增答案信息
    public function XinAnswer(){
    $this->load->view('xinzengdaan');
    }

    public function XinzengAnswer()
    {

    $a=$this->input->post('a');
    $b=$this->input->post('b');
    $c=$this->input->post('c');
    $d=$this->input->post('d');
    $e=$this->input->post('e');
    $f=$this->input->post('f');
    $num=$this->input->post('num');
    $adddata=$this->GuanliMo->XinzengAnswer($a,$b,$c,$d,$e,$f,$num);
    $this->load->view('xinzengdaan',$adddata);
    }
    //关键字搜索学生信息(编辑时)
    public function SearchStudent(){
    $userID=$this->input->post('keywords');
    $data['item']=$this->GuanliMo->SearchStudent($userID);
    //var_dump($data['item']);
    $this->load->view('administer-yonghuguanli',$data);
    }
    //关键字搜索学生信息(删除时)
    public function SearchStudents(){
    $userID=$this->input->post('keywords');
    $data['item']=$this->GuanliMo->SearchStudents($userID);
    //var_dump($data['item']);
    $this->load->view('shanchuyonghu',$data);
    }

     

     

     

    //获取试题
    public function get_Shiti($page){
    if(empty($page)||$pages)
    {
    $page=1;
    }
    else
    {
    $page=$pages;
    }
    $data['Pages_item']=$this->GuanliMo->get_Shiti($page);
    $data['Pages_item']['varable']='count(num)';
    $data['Pages_item']['pages']=$page;
    $data['Pages_item']['pagesize'] = 10;
    $data['Pages_item']['pageUrl']="index.php/GuanliCon/get_Shiti";
    var_dump($data['Pages_item']);
    $this->load->view('administer-shitiguanli',$data);
    }

     

     

     

    }
    ?>

    2.Model 层次

    GuanliMo

    代码如下:

    <?php
    class GuanliMo extends CI_Model{
    public function __construct(){
    parent::__construct();

    $this->load->database();
    }
    //学生信息读库
    public function Yonghu(){
    $sql="select * from t_user";
    $query=$this->db->query($sql);
    $result=$query->result_array();
    return $result;
    }
    public function News()
    {
    $sql="select * from activity";
    $iquery=$this->db->query($sql);
    $result=$iquery->result_array();
    return $result;
    }
    //根据传过来的id和查询一条数据
    public function get_one_activity($id)
    {
    $sql='select * from activity where ActID='.$id;
    $query = $this->db->query($sql);
    return $query->result_array();
    }

     

    //试题读库
    public function Shiti(){
    $sql="select * from question";
    $tquery=$this->db->query($sql);
    $result=$tquery->result_array();
    return $result;
    }
    //关键字查询试题
    public function SearchShiti($num){
    $sql="select * from question where num ='$num'";
    $query=$this->db->query($sql);
    return $query->result_array();
    }

    //答案读库
    public function Answer(){
    $sql="select * from answer";
    $hquery=$this->db->query($sql);
    $result=$hquery->result_array();
    return $result;
    }
    //关键字查询答案
    public function SearchAnswer($num){
    $sql="select * from answer where num='$num'";
    $query=$this->db->query($sql);
    return $query->result_array();
    }



    //删除试题
    public function ShanchuShiti($num){
    $sql="DELETE FROM question WHERE num='$num'";
    $query=$this->db->query($sql);
    return $query;
    }
    //删除学生
    public function ShanchuStudent($userID){
    $sql="DELETE FROM t_user WHERE userID='$userID'";
    $query=$this->db->query($sql);
    return $query;
    }
    //删除答案
    public function ShanchuAnswer($num){
    $sql="DELETE FROM answer WHERE num='$num'";
    //var_dump($sql);
    $query=$this->db->query($sql);
    return $query;
    }

    //修改学生信息
    public function Xiugai($userName,$usersex,$userID,$userPassword,$email)
    {
    $sql="update t_user set userName='$userName',usersex='$usersex',userID='$userID',userPassword='$userPassword',email='$email' where userID='$userID'";
    //var_dump($sql);
    $query=$this->db->query($sql);

    $csql="select * from t_user";
    $cquery=$this->db->query($csql);
    $result=$cquery->result_array();

    return $result;
    }

    //新增学生信息
    public function Xinzeng($userName,$usersex,$userID,$userPassword,$email,$worktype)
    {

    $insertsql="insert into t_user(userName,usersex,userID,userPassword,email,worktype) values('$userName','$usersex','$userID','$userPassword','$email','$worktype')";
    $query=$this->db->query($insertsql);
    return $query;

    }
    //新增试题
    public function XinzengShiti($num,$body,$type)
    {

    $insertsql="insert into question(num,body,type) values('$num','$body','$type')";
    $query=$this->db->query($insertsql);
    return $query;

    }
    //新增答案
    public function XinzengAnswer($a,$b,$c,$d,$e,$f,$num)
    {

    $insertsql="insert into answer(a,b,c,d,e,f,num) values('$a','$b','$c','$d','$e','f','$num')";
    $query=$this->db->query($insertsql);
    return $query;

    }
    //关键字查询学生(编辑时)
    public function SearchStudent($userID){
    $sql="select * from t_user where userID ='$userID'";
    $query=$this->db->query($sql);
    return $query->result_array();
    }
    //关键字查询学生(删除时)
    public function SearchStudents($userID){
    $sql="select * from t_user where userID ='$userID'";
    $query=$this->db->query($sql);
    return $query->result_array();
    }

     

    //获取试题(分页)
    /*public function get_Shiti($page){
    $sql="SELECT * FROM question order by num asc LIMIT".($page-1)*10 .",10";
    $query=$this->db->query($sql);
    return $query->result_array();
    } */

     

     


    }
    ?>

    3.界面部分view 层

    因html界面而异。

    //这些只是后台代码的一部分,可以对前台进行部分操作,是暑假时候的代码,当时对于CI框架有了一些初步了解。感觉应该经常更新博客了。。。。

  • 相关阅读:
    ORACLE创建数据库时无法创建目录
    KindEditor:Ajax提交表单时获取不到HTML内容
    mysql重置root密码
    假设检验-单样本检验
    推论统计分析-如何避免偏见和抽样分布
    推论统计分析1
    共享单车数据分析
    Kaggle泰坦尼克号生存情况预测
    R-长尾词练习
    R期望
  • 原文地址:https://www.cnblogs.com/yjm5/p/5950751.html
Copyright © 2011-2022 走看看