下载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>© 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="^(.*)" />
<conditions logicalGrouping=“MatchAll”>
<add input="{HTTP_HOST}" pattern="^(.)" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="index.php/{R:1}" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
nginx设置url取消index.php
配置nginx.conf
server{ listen 800; root /var/www/html_codeigniter; index index.html index.php; if (-f request_filename/index.php) {
rewrite (.) 1/index.php break; } if (!-e request_filename) {
rewrite (.*) /index.php;
}
location / {
try_files uri uri/ =404;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
}
}
暂无评论,还不快来坐沙发...