我有链接,
<?php foreach ($news as $news_item): ?>
<h2><?php echo $news_item['title'] ?></h2>
<div id="main">
<?php echo $news_item['text'] ?>
</div>
<?php echo base_url(); ?>
<p><a href="news/view/<?php echo $news_item['slug'] ?>"> View article </a></p>
<?php endforeach ?>
这是来自用户指南 od CodeIgniter 的代码。单击此代码的链接,它说:
未找到请求的 URL
为什么?
形成的链接是http://localhost/codeignitor/news/view/20
.
这是我的控制器:-
<?php
class news extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper("url");
$this->load->model('news_model');
}
public function index()
{
$data['news'] = $this->news_model->get_news();
$data['title'] = ' News archive ';
$this->load->view('templates/header', $data);
$this->load->view('news/index', $data);
$this->load->view('templates/footer');
}
public function view($slug)
{
$data['news'] = $this->news_model->get_news($slug);
if (empty($data['news_item']))
{
show_404();
}
$data['title'] = $data['news_item']['title'];
$this->load->view('templates/header', $data);
$this->load->view('news/view', $data);
$this->load->view('templates/footer');
}
}