我正在使用Codeigniter框架。我在应用程序/控制器中创建了一个名为“blog.php”的新Controller。这个'blog.php'有以下代码:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class blog extends CI_Controller {
public function view($page = 'blog_view')
{
$this->load->view('blog_view');
}
}
在应用程序/视图中,我创建了'blog_view.php',此文件包含以下代码:
<h1>BLOG VIEW</h1>
现在我有两个问题:
提前致谢。
答案 0 :(得分:0)
如果你不使用.htaccess试试这个 http://localhost/ci/index.php/blog
要删除index.php,请在ci文件夹中创建.htaccess文件并将此代码放入其中
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
添加更多页面添加更多控制器,例如创建关于页面
创建名为
的新控制器 <?php
defined('BASEPATH') OR exit('No direct script access allowed');
class about extends CI_Controller {
public function view($page = 'blog_view')
{
$this->load->view('about_view');
}
}
和视图
<h1>About VIEW</h1>