±¾ÎÄʵÀý×ܽaÁËCI¿o¼Ü³£Óþµa²Ù×÷Àa¡£*ÖÏi¸ø´o¼Ò¹(C)´o¼Ò²Î¿¼£¬¾ßÌaÈçÏ£º
1. ³¬¼¶¶ÔÏoÖеÄURI
CI_URIÀaµÄ½aÎourlµÄÏa¹ØÐÅÏ¢
Ö±½ÓʹÓÃ$this->uri¿ÉÒÔʹÓÃËuµÄÏa¹ØÊoÐÔ
system/core/URI.phpÎļþÖÐ
²¿*Ö³£ÓÃÊoÐÔ£º
(1) *ֶλñÈ¡urlÏa¹ØÐÅÏ¢
$this->uri->segment(4);
//»ñÈ¡urlÖÐpathinfo
//µÄµÚËĶεÄÖµ
Èe¿ÚÎļþ.php/¿ØÖÆÆ÷/¶¯×÷/²ÎÊý1/²ÎÊý2/...
(2) ͨ¹ý½¨ÖеÄÐβδ«²Î
ÐeÒªÉeĬÈÏÖµºÍ˳ÐoҪעÒa
index.php/user/index/3/zhangsan
public function index($id=0,$name=''){
echo $id,$name;
}
2.CI¿ØÖÆÆ÷µÄÀ(C)Õ¹
ÔÚapplication/core/Îļþ¼ÐÏÂÃae
Ìi¼Ó×Ô¼ºµÄÀ(C)Õ¹¿ØÖÆÆ÷
class MY_Controller extends CI_Controller{
public function __construct(){
parent::__construct
}
}
ÅaÖÃÄ£ÐÍǰ׺
$config['subclass_prefix']='MY_';//ĬÈÏÖµ
3.Ä£Ð͵ÄÏa¹Ø²Ù×÷
ÎļþÃuȫСд£¬ÀaÃuÊ××Öĸ´oд
½¨ÒeÀaÃu¼ÓÉÏ _modelºo׺
ÔÚ¿ØÖÆÆ÷ÖмÓÔØÄ£ÐÍ£º
ÔÚconstructÖмÓÈe£º
$this->load->model('User_model');
$this->User_model->get();
ΪģÐÍÆð±ðÃu
$this->load->model('User_model','user');
$this->user->get();
4.urlÖеij£Óú¯Êý
(1)°iÖuÎÒÃÇÉu³É¿ØÖÆÆ÷
$this->load->helper('url');
site_url('¿ØÖÆÆ÷/*½*¨');
(2)ͼƬÂ*¾¶µÄʹÓÃ
$this->load->helper('url');
<img src="<?php echo base_url();?>upload/a.jpg" />
¿ÉÒÔÔÚautoload.phpÖÐÅaÖÃ×Ô¶¯¼ÓÔØ
$autoload['helper']¼ÓÈeurl
*5. CIÖеÄÂÓÉÓeα¾²Ì¬**
(1) Â*ÓÉα¾²Ì¬
$router['show/([\d]+)\.html']='article/show/$1';
article/show/5.html => article/show/5;
(2) Òþ²ØÈe¿ÚÎļþ
#¿ªÆoapacheµÄrewriteÄ£¿e
#ÔÚ¸uĿ¼ÖÐ*ÅÈe.htaccessÎļþ½øÐÐÖØд
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
*6. CIÖеÄÖÒ³**
//Ä£ÐÍÖвÙ×÷
//×°ÔØ*ÖÒ³ÀaÎļþ
$this->load->library('pagination');
$this->load->helper(url);
//*ÖÒ³Á´½Ó
$config['base_url'] = site_url('user/test');
//×ܼǼÌoÊý
$config['total_rows'] = 100;
//ÿҳÏÔʾ10ÌoÊý¾Ý
$config['per_page'] = 10;
//Æ«ÒÆÁ¿
$offset_limit = intval($this->uri->segment(3));
$this->pagination->initialize($config);
echo $this->pagination->create_links();
*ÖÒ³Öа´Å¥µÄ¶¨ÖÆ(×¢ÒaÔÚ³oʼ»¯Ö®Ç°ÅaÖúÃ)
$config['first_link'] = 'Ê×Ò³';
...
$config['uri_segment'] =3;//*ÖÒ³Êý¾Ý²eѯƫÒÆÁ¿
ÔÚurlµÄÄÄÒ»¶ÎÉÏ£¬¶ÔÓ¦ÉÏÃaeµÄ$offset
ĬÈÏÊÇ3£¬*ñÔoÐeÒªÐ޸ĶÔÓ¦Öµ
7. CI ÖÐsessionµÄʹÓÃ
//¼ÓÔØsession¿a
$this->load->library('session');
(1)»ñȡϵͳsession
//±ÈÈç»ñÈ¡¿Í»§¶ËµÄipµØÖ*
$this->session->userdata('ip_address');
(2) Ìi¼Ó×Ô¶¨Òasession
//Ìi¼Ó
$this->session->set_userdata('some_name', 'some_value');
//»ñÈ¡
$this->session->userdata('some_name');
//ɾ³ý
$this->session->unset_userdata('some_name');
(3)ÉÁ³oÊý¾Ý £¨È¡³oÒ»´ÎºoʧЧ£(C)
//Ìi¼Ó
$this->session->set_flashdata('item', 'value');
//»ñÈ¡
$this->session->flashdata('item');
µÇ¼Êý¾ÝÖÐ *µ»ØµÇ¼ǰµÄÄÇÒ»¸oÒ³ÃaeµÄurl¿ÉÒԼǼÏÂÀ´£¬
×¢Òa£ºÒ»´ÎÐÔµÄÊý¾Ý£¬¶ÁÈ¡Ò»´Îºo»a×Ô¶¯Ïu»Ù¡£
ΪÁËȱ£°²È«£¬ÔÚconfig.phpÉu³ÉËae»u¼ÓÃܵÄ×Öu´®ÖмÓÈe
$config['encryption_key']="fjkdsffjkhjd#kjh";
ÊÇ*ñÒª½«cookie¼ÓÃÜ
$config['sess_encrypt_cookie'] =TRUE;
8. CIÖеÄÎļþÉÏ´«
<form action="<?php echo site_url('user/upload');?>" enctype="multipart/form-data">
<input type="file" name="pic"/>
<input type="submit" value="submit">
</form>
ÉÏ´«´¦Ài£º
$config['upload_path']="./upload";
$config['allowed_types']='gif|jpeg|jpg';
$this->load->library('upload',$config);
$this->upload->do_upload('pic');
ÎļþÉÏ´«µÄÊý¾Ý
$filedata = $this->upload->data();
9. CIÖеÄÑeÖ¤Âe
//Éu³ÉÑeÖ¤Âe
$this->load->helper('captcha');
$this->load->helper('url');
$vals = array(
'word'=>rand(1000,9999),
'img_path'=>'./captcha/',
'img_url'=>base_url().'/captcha/'
'img_width'=>'150',
'img_height'=>'100',
'expiration'=>7200
);
$cap = create_captcha($vals);
echo $cap['image'];
//½«ÑeÖ¤Âe»ñÈ¡µÄÊý×Ö*ÅÔÚsessionÖÐ
session_start();
$_SESSION['cap'] = $cap['word'];
¸u¶a¹ØÓÚCodeIgniterÏa¹ØÄÚÈݸÐÐËȤµÄ¶ÁÕ߿ɲe¿´±¾Õ¾×¨Ìa£º¡¶codeigniterÈeÃŽ̡̳¡¢¡¶CI(CodeIgniter)¿o¼Ü½ø½×½Ì³Ì¡¡¢¡¶phpÓÅÐa¿ª*¢¿o¼Ü×ܽa¡¡¢¡¶ThinkPHPÈeÃŽ̡̳¡¢¡¶ThinkPHP³£Óý¨×ܽa¡¡¢¡¶Zend FrameWork¿o¼ÜÈeÃŽ̡̳¡¢¡¶phpÃaeÏo¶ÔÏo³ÌÐoÉe¼ÆÈeÃŽ̡̳¡¢¡¶php+mysqlÊý¾Ý¿a²Ù×÷ÈeÃŽ̡̳¼°¡¶php³£¼uÊý¾Ý¿a²Ù×÷¼¼ÇÉ»a×Ü¡*
Ï£Íu±¾ÎÄËuÊo¶Ô´o¼Ò»uÓÚCodeIgniter¿o¼ÜµÄPHP³ÌÐoÉe¼ÆÓÐËu°iÖu¡£