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里面的数据

posted @ 2013-08-28 15:04  竹三戒  阅读(185)  评论(0编辑  收藏  举报