锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
2.鎺у埗鍣ㄥ悜view浼犻掑弬鏁?br /> $data = Array("name"=>$name,"count"=>$count);
]]>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
</head>
<body>
<center>
<h1><?php $this->load->view('index.html');?></h1>
<h1>鐢ㄦ埛鐧婚檰</h1>
<form action="/php/myweb/index.php/login/logina" method="post">
鐢ㄦ埛鍚? <input type="text" name="username"/><br />
瀵?nbsp; 鐮? <input type="password" name="password"/><br />
<input type="submit" value="鎻愪氦"><br />
</form>
</center>
</body>
</html>
class Login extends CI_Controller
{
function index()
{
$this->load->view ( "aa/user_login" );
}
function logina()
{
$this->load->model('user_model');
$user = $this->user_model->user_find_by_username ( $_POST ['username'] );
if ($user)
{
if ($user [0]->password == $_POST ['password'])
{
$arr = Array ('id' => $user [0]->id );
$this->load->library ( 'session' );
$this->session->set_userdata ( $arr );
echo 'aa<br />';
echo $this->session->userdata ( 'id' );
}
else
{
echo '瀵嗙爜涓嶆紜?;
}
}
else
{
echo "鐢ㄦ埛鍚嶄笉瀛樺湪";
}
// var_dump($reult);
// echo $reult[0]->username;
}
function check_login()
{
$this->load->library ( 'session' );
if ($this->session->userdata ( 'id' ))
{
echo '宸茬粡鐧婚檰';
}
else
{
echo '娌℃湁鐧婚檰';
}
}
function login_out()
{
$this->load->library ( 'session' );
$this->session->unset_userdata ( 'id' );
}
}
3.userControl
class User extends CI_Controller
{
function insert()
{
$this->load->model('user_model');
$arr = Array('username'=>'hwpok', 'password'=>'123456');
$this->user_model->user_insert($arr);
}
function update()
{
$this->load->model('user_model');
$id = 2;
$arr = Array('username'=>'hwpokay', 'password'=>'123456');
$this->user_model->user_update($id, $arr);
}
function del()
{
$this->load->model('user_model');
$id = 4;
$this->user_model->user_del($id);
}
function find()
{
$this->load->model('user_model');
$id = 2;
$reult = $this->user_model->user_find($id);
//var_dump($reult);
echo $reult[0]->username;
}
}
4. userModel
class User_model extends CI_Model {
function __construct()
{
parent::__construct ();
$this->load->database ();
}
function user_insert($arr)
{
$this->db->insert ( 'php_t_user', $arr );
}
function user_update($id, $arr)
{
$this->db->where('id',$id);
$this->db->update('php_t_user',$arr);
}
function user_del($id)
{
$this->db->where('id',$id);
$this->db->delete('php_t_user');
}
function user_find($id)
{
$this->db->where('id',$id);
$this->db->select('*');
$res = $this->db->get('php_t_user');
return $res->result();
}
function user_find_by_username($username)
{
$this->db->where('username',$username);
$this->db->select('*');
$res = $this->db->get('php_t_user');
return $res->result();
}
}
]]>
2 if (! defined ( 'BASEPATH' ))
3 exit ( 'No direct script access allowed' );
4 class Hello extends CI_Controller {
5 public function sayHello() {
6 $name = "huiwanpeng";
7 @$count =file_get_contents('./num.txt');
8
9 $count = $count ? $count : 0;
10 $count = $count + 1;
11
12 $re = fopen('./num.txt', 'w');
13 fwrite($re, $count);
14 fclose($re);
15
16 $data = Array("name"=>$name,"count"=>$count);
17 $this->load->view ( "test_view",$data);
18 //echo "helloa";
19 }
20 }
view
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<?php echo $name ?>
<?php echo $count ?>
</body>
</html>
]]>
閲岄潰閰嶇疆鐜
涓銆嬪湪linux閲岄潰璁劇疆
1.鎵撳紑apache鐨勯厤緗枃浠訛紝conf/httpd.conf 錛?/p>
LoadModule rewrite_module modules/mod_rewrite.so錛屾妸璇ヨ鍓嶇殑#鍘繪帀銆?br />鎼滅儲 AllowOverride None錛堥厤緗枃浠朵腑鏈夊澶勶級錛岀湅娉ㄩ噴淇℃伅錛屽皢鐩稿叧.htaccess鐨勮琛屼俊鎭敼涓篈llowOverride All銆傘愬叾瀹瀉pache 榛樿鐨勯兘宸茬粡鎵撳紑鐨勩?/p>
2.鍦?strong style="color: black; background-color: #ffff66;">CI鐨勬牴鐩綍涓嬶紝鍗沖湪index.php錛宻ystem鐨勫悓綰х洰褰曚笅錛屽緩绔?htaccess錛岀洿鎺ュ緩绔嬭鏂囦歡鍚嶄笉浼氭垚鍔燂紝鍙互鍏堝緩绔嬭浜嬫湰鏂囦歡錛屽彟瀛樹負璇ュ悕鐨勬枃浠跺嵆鍙傚唴瀹瑰涓嬶紙CI鎵嬪唽涓婁篃鏈変粙緇嶏級錛?br />RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
濡傛灉鏂囦歡涓嶆槸鍦╳ww鐨勬牴鐩綍涓嬶紝渚嬪鏄細http://localhost/nianyi_2011/index.php,絎笁琛?/p>
闇瑕佹敼鍐欎負RewriteRule ^(.*)$ /nianyi_2011/index.php/$1 [L]
鍙﹀錛屽鏋滀綘鐨勭綉绔欑殑鏍圭洰褰曚笅闈㈣繕鏈夊叾浠栫殑鏂囦歡澶癸紝渚嬶細js錛宑ss錛宨mages錛宑onfig絳夌瓑鏂囦歡澶癸紝榪欓渶瑕佽繃婊ら櫎鍘伙紝絎簩琛岄渶瑕佹敼鍐欎負錛?br />RewriteCond $1 !^index\.php|images|js|css|config|robots\.txt)銆?br />3.灝?strong style="color: black; background-color: #ffff66;">CI涓厤緗枃浠訛紙application/config/config.php錛変腑$config['index_page'] ="index.php";鏀瑰啓鎴?config['index_page'] = "";
4.ok錛屽畬鎴愩傝繕瑕佽寰楅噸鍚痑pache銆?/p>
浜屻嬪湪windows閲岄潰寮鍙?/p>
浠ヤ笂鐨勯厤緗湪windows涓婇潰鏄笉璧蜂換浣曚綔鐢ㄧ殑錛屾墍浠ユ垜浠湪windows閲岄潰闇瑕佽緗垜浠殑apache鐨勮櫄鎷熶富鏈猴紝鍦╝pache閲岄潰鎵懼埌Apache-20\conf\extra\httpd-vhosts.conf 榪欎釜鏂囦歡銆愭垜鐢ㄧ殑鏄湇鍔℃槸PHPnow錛屽緢澶氱殑浜虹敤wamp銆戯紝鍚屾牱鎵懼埌姝ゆ枃浠訛紝鍦ㄩ噷闈慨鏀癸紝渚嬶細
#http://www.PHPnow.org
# filename: httpd-vhosts.conf
<Directory ../vhosts>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
NameVirtualHost *
<VirtualHost *>
DocumentRoot ../htdocs
ServerName default:80
ErrorLog logs/default-error_log
</VirtualHost>
淇敼鎴愶細
#http://www.PHPnow.org
# filename: httpd-vhosts.conf
<Directory ../vhosts>
RewriteEngine on
RewriteCond $1 !^(index\.php|images|js|css|config|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
AllowOverride All
Order allow,deny
Allow from all
</Directory>
NameVirtualHost *
<VirtualHost *>
DocumentRoot ../htdocs
ServerName default:80
ErrorLog logs/default-error_log
</VirtualHost>
涔熷氨鏄妸璺敱鍐欏埌榪欓噷闈㈡潵銆傝寰楅噸鏂板惎鍔ㄦ湇鍔°?/p>
緇х畫淇敼浣犵殑閰嶇疆鏂囦歡錛?br />$config['enable_query_strings'] = true
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
鎶?config['enable_query_strings'] 淇敼鎴?false 榪欐牱灝卞叧闂簡鏌ヨ瀛楃涓插艦寮?URL
鐜板湪浣犵殑鏂囦歡鐨勮礬寰勫氨鍙互鍐欏緱浜嗭紝渚嬪錛?a href="http://localhost/nianyi_2011/user/user_point" style="color: #3fa7cb;">http://localhost/nianyi_2011/user/user_point
灝辯浉褰撲簬鍏堝墠娌℃湁閰嶇疆鐨勮礬鐢憋細http://localhost/nianyi_2011/index.php?c=user&m=user_point鍚屾牱濡傛灉鍚庨潰鏈夊弬鏁扮殑璇濓紝鍙敤寰鍚庝竴嬈$瘡鍔犲氨濂界殑浜嗐?/p>
璇鋒敞鎰忥細鏈夋椂鍊欐垜浠繖鏍峰啓涔嬪悗鏍峰紡鏂囦歡鍔犺澆榪涙潵浼氭湁闂錛屾壘涓嶅埌js css images絳夌瓑鐩綍錛屾垜浠彲浠ラ厤緗枃浠禼onfig.php閲岄潰璁劇疆$config['base_url'] = 'http://localhost/2011_11_cms/';绔欑偣鐨勭洰褰曪紝鎺ョ潃鎴戜滑鍦╲iew妯℃澘鏂囦歡<head></head>涔嬮棿娣誨姞<base href="<?=base_url()?>" />錛岃繖鏍峰氨鑳藉姞杞藉叾浠栫殑鏂囦歡鐨勪簡