我已经在我的 localhost xampp 服务器上的目录中安装了 CodeIgniter:
localhost/CI/
当我直接访问该目录时,我会看到主页,但是当我尝试访问任何其他页面时,我会得到一个基于服务器的404
页面。我没有看到 CI 404。
我已经尝试过使用,uri_protocol
但我无法让它工作。有什么线索吗?
路由.php
$route['page/create'] = 'page/create';
$route['(:any)'] = 'page/view/$1';
$route['default_controller'] = 'page/view/hello-world';
$route['404_override'] = '';
页面控制器
class Page extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('page_model');
}
public function view($slug)
{
$data['page'] = $this->page_model->get_page($slug);
if (empty($data['page']))
{
show_404();
}
$data['title'] = $data['page']['title'];
$this->load->view('templates/header', $data);
$this->load->view('page/view', $data);
$this->load->view('templates/footer');
}
public function create()
{
$this->load->helper('form');
$this->load->library('form_validation');
$data['title'] = 'Create a new page';
$this->form_validation->set_rules('title', 'Title', 'required');
if ($this->form_validation->run() === FALSE)
{
$this->load->view('templates/header', $data);
$this->load->view('page/create');
$this->load->view('templates/footer');
}
else
{
$this->page_model->set_page();
$this->load->view('page/success');
}
}
}
“世界你好!” 显示很好,但我无法让创建页面工作。该视图位于views/page/create.php