CI框架入门教程

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文件的方法,另存文件的时候,文件名加上双引号。
   CI框架入门教程
$this->router->fetch_class();  //获取当前的类名
$this->router->fetch_method();  //获取当前的方法名
$this->router->fetch_diretory();  //获取当前的目录
 
3.验证码
   参考:http://v.youku.com/v_show/id_XNjE0NjUzNTY4.html
 
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'] = " ";        //换行符
        $config['newline'] = " ";    //换行符
        $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();
原文地址:https://www.cnblogs.com/houdj/p/7927389.html