【问题标题】:In codeigniter, I created static page but still I am getting only Index.php Welcome Message在 codeigniter 中,我创建了静态页面,但我仍然只收到 Index.php 欢迎消息
【发布时间】:2013-04-12 12:48:53
【问题描述】:

我已经安装了 CodeIgniter_2.1.3 并在

中运行
  • Windows 7
  • Wamp 服务器 2.1
  • PHP 5.3.5
  • Apache 2.2.17

我关注了 Codeignitor 中提供的 Codeignitor Static Pages Tutorial 链接。

我在 application/controllers/pages.php 中创建了文件,其中包含以下代码。

<?php class Pages extends CI_Controller 
{

    public function view($page = 'home')
    {

        if ( ! file_exists('application/views/pages/'.$page.'.php'))
        {
            // Whoops, we don't have a page for that!
            show_404();
        }

        $data['title'] = ucfirst($page); // Capitalize the first letter

        $this->load->view('templates/header', $data);
        $this->load->view('pages/'.$page, $data);
        $this->load->view('templates/footer', $data);

    }
}
?>

然后我在 application/views/templates/header.php 创建了标题,代码如下:

<html>
<head>
    <title><?php echo $title ?> - CodeIgniter 2 Tutorial</title>
</head>
<body>
    <h1>CodeIgniter 2 Tutorial</h1>

然后我使用以下代码在 application/views/templates/footer.php 创建了一个页脚:

<strong>&copy; 2011</strong>    
</body>
</html>

然后当我打电话给http://localhost/CodeIgniter_2.1.3/index.php/pages/view/home

我得到了这个作为输出

欢迎使用 CodeIgniter!

您正在查看的页面是由 CodeIgniter。

如果您想编辑此页面,您可以在以下位置找到它: 应用程序/views/welcome_message.php

此页面对应的控制器位于: 应用程序/控制器/welcome.php

如果您是第一次探索 CodeIgniter,您应该 首先阅读用户指南。

而不是获取带有附加 header.php 和 footer.php 的 home.php。

我怀疑这是因为 codeignitor 配置或 php 配置或 apache 服务器配置中的一些错误设置。

【问题讨论】:

  • 你为什么不尝试去http://localhost/CodeIgniter_2.1.3/index.php
  • 谢谢。我现在可以输入每个页面。我只是将 base_uel 设置为空白。我将 index_page 设置为 index.php。我现在使用 codeigniter 表单函数。

标签: php codeigniter apache2


【解决方案1】:

如果您像这样调用http://localhost/CodeIgniter_2.1.3/,那么您必须从您的routes.php 中删除默认控制器。它应该是空的。默认情况下,它设置了欢迎控制器。

$route['default_controller'] = "" // Replace with your default controller;

routes.php 将位于 config 文件夹中。

【讨论】:

  • 谢谢。我现在可以输入每个页面。我只是将 base_uel 设置为空白。我将 index_page 设置为 index.php。我现在使用 codeigniter 表单函数。
【解决方案2】:

转到 application/config/routes.php

$route['default_controller'] = "pages";

希望对你有帮助 然后去

/CodeIgniter_2.1.3/index.php/pages/view

【讨论】:

  • 谢谢。我现在可以输入每个页面。我只是将 base_uel 设置为空白。我将 index_page 设置为 index.php。我现在使用 codeigniter 表单函数。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
  • 2023-03-28
  • 2020-03-16
  • 1970-01-01
相关资源
最近更新 更多