无法在Codeigniter中访问新创建的“查看”页面

时间:2015-03-22 07:06:41

标签: php codeigniter

我正在使用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>

现在我有两个问题:

  1. 如何在网址中访问此blog_view页面?我的项目名称是'ci'。当我访问'localhost / ci'时,我可以查看“欢迎”页面。
  2. 如何添加其他网页的链接,例如博客页面中的“关于”页面?例如,在静态网站中,我们在href。
  3. 中添加了带有about.html的锚标记

    提前致谢。

1 个答案:

答案 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]

http://localhost/ci/blog

添加更多页面添加更多控制器,例如创建关于页面

创建名为

的新控制器
 <?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>