zoukankan      html  css  js  c++  java
  • CI 基础

    Welcome 控制器

     1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
     2 
     3 class Welcome extends CI_Controller {
     4   public function index(){
     5     $this->load->view('index_index');
     6   }
     7   public function haha(){
     8     $this->load->view('index_haha');
     9   }
    10 }

    http://moumou.com/

    http://moumou.com/index.php/welcome/haha/

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

    .htaccess

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]

    http://moumou.com/

    http://moumou.com/welcome/haha/

    =============================================================
    修改/application/config/routes.php

    //$route['default_controller'] = "welcome";
    $route['default_controller'] = "game";

    http://moumou.com/

    http://moumou.com/game/haha

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

    game 控制器

     1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
     2 
     3 class game extends CI_Controller {
     4   public function index(){
     5     $this->load->view('game_index');
     6   }
     7   public function haha(){
     8     $this->load->helper('url');
     9     $haha['data'] = $this->uri->segment(3);
    10     $this->load->view('game_haha',$haha);
    11   }
    12 }

    http://moumou.com/game/haha/2

    $this->uri->segment(3) 为2

    -----------------------------
    修改/application/config/routes.php
    添加

    $route['url/(:num)'] = "game/haha";

    http://moumou.com/url/2

    $this->uri->segment(3) 为空
    $this->uri->segment(2) 为2

    --------------------------------------------------

    修改

    $route['url/(:any)'] = "game/haha";

    http://moumou.com/url/cv2.html

    -------------------------------------------------

    两个控制器的

    $route['g/(:any)'] = "game/haha";
    $route['f/d/(:any)'] = "fuck/kao";

    -------------------------------------------------

    同一个控制器的两个方法

    $route['gi/(:any)'] = "game/index";
    $route['gh/(:any)'] = "game/haha";

    【以上都要注意 $this->uri->segment(n)】

    ===============================================================
    修改/application/config/routes.php

    //$config['url_suffix'] = '';
    $config['url_suffix'] = '.html';

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

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

    game 控制器

     1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
     2 
     3 class game extends CI_Controller {
     4   public function index(){
     5     $this->load->helper('url');
     6     $index['data'] = "数据";
     7     $index['title'] = "这是标题";
     8     $this->load->view('game_index_head',$index);
     9     $this->load->view('game_index_body');
    10     $this->load->view('game_index_foot');
    11   }
    12 }

    在第一个里面传递$index就行,即使head,body里面都调用index里面的数据

  • 相关阅读:
    沮丧
    实例讲解《Microsoft AJAX Library》(1):DomElement类
    linux0.12系统调用
    关于中断
    dd写img
    linux系统中堆栈的使用方法
    浅析程序的装载
    SourceInsight3.5序列号
    区分进程的逻辑地址空间中段和cpu分段机制中段的概念
    32位计算机的4G可寻址空间
  • 原文地址:https://www.cnblogs.com/zhusanjie/p/3287223.html
Copyright © 2011-2022 走看看