后盾网-CI框架实例教程-马振宇 - 学习笔记(3)

第三节视频:

  1、配置自动加载辅助函数URL:

    在application/config/autoload.php中设置:

      $autoload['helper'] = array('url');

  2、配置默认控制器:

    在application/controllers下新建两个文件夹index和admin,用以区分前台和后台的控制器;

    在application/controllers/index/下新建home.php

    在application/config/routes.php里面修改默认的控制器:

      $route[‘default_controller’] = 'welcome';

     修改为:

      $route['default_controller'] = 'index/home';

   此版本为CodeIgniter 2.2.6,CodeIgniter 3.1.6版本不支持以上操作;

  3、载入模板:

    在application/views下新建两个文件夹index和admin,用以分别存放前台模板和后台模板;

    在ci文件夹下新建文件夹style,并在style里面新建两个文件夹index和admin,用以分别存放前台和后台的样式;

    在模板中引用样式时,使用 <?php echo base_url().'style/index/' ?>css/index.css

    <link href="<?php echo base_url().'/style/index/'?>css/index.css" rel="stylesheet" />

 

  4、如何引入分类页:

    在控制器中载入分类页模板:

    class Home extends CI_Controller{

      // 默认首页显示方法
      public function index(){
        $this ->load ->view('index/index.html');
      }

      // 分类页显示方法
      public function category(){
        $this ->load ->view('index/category.html');
      }
    }

    在首页模板中引入分类页的地址:

      <a href="<?php echo site_url().'/index/home/category'; ?>">青春</a>

  5、如何在分类页中引入文章阅读页:

    在Home 控制器中载入文章阅读页的模板:

      // 文章阅读页显示方法
     public function details(){
      $this ->load ->view('index/details.html');
     }

    在分类页中引入文章阅读页的地址:

      <a href="<?php echo site_url().'/index/home/details'?>" class='more'>更多>></a>

 

  ===================================

 

  6、载入后台模板:

    在application/controller/admin下新建控制器admin.php

    在Admin控制器中载入后台首页:

      class Admin extends CI_Controller{

        // 后台首页方法
        public function index(){
          $this ->load ->view('admin/index.html');
        }
      }

    在后台首页中引入后台样式:

      <link rel="stylesheet" href="<?php echo base_url().'style/admin/'?>css/admin.css" />

   7、在后台模板中载入默认欢迎页:(此为iframe)

        //默认欢迎
      public function copy(){
        $this ->load ->view('admin/copy.html');
      }

    在默认欢迎页中引入样式:

      <link rel="stylesheet" href="<?php echo base_url().'style/admin/'?>css/admin.css" />

   8、在application/controller/admin/下新建控制器login.php,用以写入登录方法:

      //后台登录控制器
      class Login extends CI_Controller{
      //登录默认方法
        public function index(){
          $this ->load ->view('admin/login.html');
        }
      }

    在后台登录页面中引入样式:

      <link rel="stylesheet" href="<?php echo base_url().'style/admin/'?>css/login.css" />

 

      

    

  

posted @ 2017-10-07 07:54  一纸流年  阅读(354)  评论(0编辑  收藏  举报