dousigan0499 2013-04-12 12:48
浏览 115

在codeigniter中,我创建了静态页面但仍然只获得了Index.php欢迎消息

I have installed CodeIgniter_2.1.3 and running in

  • Windows 7
  • Wamp Server 2.1
  • PHP 5.3.5
  • Apache 2.2.17

I followed this Codeignitor Static Pages Tutorial link provided in Codeignitor.

I created, file at application/controllers/pages.php with the following code.

<?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);

    }
}
?>

and then I created the header at application/views/templates/header.php with code as below:

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

and then i created a footer at application/views/templates/footer.php with the following code:

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

and then when i called http://localhost/CodeIgniter_2.1.3/index.php/pages/view/home

I got this as output

Welcome to CodeIgniter!

The page you are looking at is being generated dynamically by CodeIgniter.

If you would like to edit this page you'll find it located at: application/views/welcome_message.php

The corresponding controller for this page is found at: application/controllers/welcome.php

If you are exploring CodeIgniter for the very first time, you should start by reading the User Guide.

instead of getting the home.php with appended header.php and footer.php.

I suspect this is because of some wrong settings in either in codeignitor config or in php config or apache server config.

  • 写回答

2条回答 默认 最新

  • doudouchan5830 2013-04-12 12:52
    关注

    If you are calling like this http://localhost/CodeIgniter_2.1.3/, then you have to remove default controller from your routes.php. It should be empty. By default it is set up with welcome controller.

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

    routes.php will be inside config folder.

    评论

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3