CI框架是一个小巧,性能优良的php框架。
1.
URL常用的相关函数
url相关函数在辅助类url中第一,要使用它们必须先加载$this->load->helper('url')或者自动装载
site_url('控制器/方法..') ,用于生成URL路径
base_url()
获取网站的根目录,注意网站的根目录不是服务器的根目录。
2.路由部分
(1)
修改默认控制器
$route['default_controller']="manage"; //
config/routes.php文件
(2)
配置路由规则
比如:$route['article/(\d+)\.html']='manage/index/$1'; // $1 是(\d+)
通过路由规则,可以让index.php/article/123.html
路由到index.php/manage/index/123上面,当然在实际的项目中,我们根据不同的需求,制定不同的路由规则来满足项目开发的要求。
(3)
去掉index.php 入口文件
apache的重写规则可以直接去掉index.php
首先在httpd.conf文件中打开重写规则,LoadModule rewrite_module
modules/mod_rewrite.so 去掉前面
的#注释,在网站根目录下面,放置.htaccess文件
.htaccess 加上以下代码
RewriteEngine on
RewriteCond
%{REQUEST_FILENAME} !-d
RewriteCond
%{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$
index.php/$1 [L]
最后一步,重启apache
附录:window下创建.htaccess文件的方法,另存文件的时候,文件名加上双引号。
$this->router->fetch_class();
//获取当前的类名
$this->router->fetch_method();
//获取当前的方法名
$this->router->fetch_diretory();
//获取当前的目录
3.验证码
参考:
4.CI框架导致的403 状态错误
CI默认的.htaccess文件有问题,需要修改过来
参考:
RewriteEngine on
RewriteCond
%{REQUEST_FILENAME} !-f
RewriteCond
%{REQUEST_FILENAME} !-d
RewriteCond $1
!^(index\.php|js|css|images|robots\.txt)
RewriteRule ^(.*)$
/index.php/$1 [L]
5.发送邮件
//邮件发送
$config['protocol']='smtp';
//邮件发送协议
$config['smtp_host']='smtp.163.com';
//SMTP 服务器地址
$config['smtp_user']='xx@163.com';
//SMTP 用户名
$config['smtp_pass']='xx';
//邮箱密码
$config['mailtype']='text';
$config['validate']=TRUE;
//是否验证邮件地址
$config['charset']='utf-8';
//iso-8859-1
$config['wordwrap']=TRUE;
//是否启用自动换行
$config['crlf']="\r\n";
//换行符
$config['newline']="\r\n";
//换行符
$config['smtp_port']=25;
//SMTP
端口
$config['smtp_timeout']=10;
$this->load->library('email',
$config);
$this->email->from('xx@163.com',
'来自纽戴尔安全中心'); //发送人
$this->email->to($email['email']);
//接收人
$this->email->subject('安全中心-找回密码');
//主题
$this->email->message($message);
$this->email->send();
如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h60240.shtml