HEANNY.CN

  • Home
  • Blog196
  • Shares29
  • Portfolio58
  • Gbook45
  • About
  • Sign In

MAIL:lzh#heanny.cn Copyright © 2008-2017 冀ICP备18027130号 V3.2.180914

【自学自用】CodeIgniter的学习与记录

2019-11-27 74
    codeigniterphpapacheiis


官网https://codeigniter.org.cn/


下载https://codeigniter.org.cn/user_guide/installation/downloads.html


环境:php>=5.3

模式:MVC

一、Controller:application/controllers/Blogs.php

<?php
class Blogs extends CI_Controller
{
    public function view($page = 'home')
    {
//        if (!file_exists(APPPATH . 'views/blogs/' . $page . '.php')) {
//            echo '404';
//            show_404();
//        }
        $data['title'] = ucfirst($page);
        $this->load->view('templates/header', $data);
        $this->load->view('blogs/' . $page, $data);
        $this->load->view('templates/footer', $data);
    }
}
?>

二、model:application/models/Blogs_model.php

<?php
class Blogs_model extends CI_Model {

    public function __construct()
    {
        $this->load->database();
    }
}
?>

//待完善

三、view:application/views/blogs/home.php

<div>
    hello blogs home page
</div>

//待完善


四、其他

header:

<html lang="en">
    <head>
        <title>CodeIgniter Tutorial</title>
    </head>
    <body>
        <h1><?=$title?></h1>

footer:

<em>&copy; 2008-2019</em>
</body>
</html>

Apache设置url取消index.php

编写文件:

.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|images|public|assets|robots\.txt)  //不转发的类型及目录
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

IIS设置url取消index.php

编写配置文件:

web.config

<?xml version="1.0" encoding="UTF-8"?>

<configuration>
   <system.webServer> 
        <rewrite>
            <rules>
                <rule name="OrgPage" stopProcessing="true">
                    <match url="^(.*)$" />
         &nbs