我已经安装了CodeIgniter_2.1.3并在
中运行- Windows 7
- Wamp Server 2.1 PHP 5.3.5 Apache 2.2.17
我遵循Codeignitor中提供的Codeignitor静态页面教程链接。
我在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>© 2011</strong>
</body>
</html>
然后调用http://localhost/CodeIgniter_2.1.3/index.php/pages/view/home
我得到了这个作为输出
欢迎使用CodeIgniter!
您正在查看的页面是由CodeIgniter .
如果你想编辑此页,你可以找到它位于:应用程序/视图/welcome_message.php
此页对应的控制器位于:应用程序/控制器/welcome.php
如果你是第一次探索CodeIgniter,你应该从阅读用户指南开始。
而不是得到附加了header.php和footer.php的home.php。
我怀疑这是因为在codeignitor配置或php配置或apache服务器配置中的一些错误设置。
如果您像这样调用http://localhost/CodeIgniter_2.1.3/
,那么您必须从routes.php
中删除默认控制器。它应该是空的。默认情况下,它设置了欢迎控制器。
$route['default_controller'] = "" // Replace with your default controller;
routes.php将放在config文件夹中。
进入application/config/routes.php
$route['default_controller'] = "pages";
希望这对你有帮助然后转到
/CodeIgniter_2.1.3/index.php/pages/view