【问题标题】:CI 2.1.1 documentation The page you requested was not foundCI 2.1.1 文档 找不到您请求的页面
【发布时间】:2016-05-23 05:49:08
【问题描述】:

我有一步一步地关注新闻部分的文档。在新闻中,CI 可以打开数据库中的数据。在数据库中有2个这样的数据 Put news data from database

在那里,有查看文章链接。但点击链接后,CI打开错误404这样 News Item from View article

可以帮我解决问题吗?对不起,我的英语不好

News_model.php

<?php
class News_model extends CI_Model {

	public function __construct()
	{
		$this->load->database();
	}
        
        public function get_news($slug = FALSE)
        {
            if ($slug === FALSE)
            {
                    $query = $this->db->get('news');
                    return $query->result_array();
            }

            $query = $this->db->get_where('news', array('slug' => $slug));
            return $query->row_array();
        }
}

控制器(News.php)

<?php
class News extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
		$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');
	}
}

新闻视图中的Index.php

<?php foreach ($news as $news_item): ?>

    <h2><?php echo $news_item['title'] ?></h2>
    <div id="main">
        <?php echo $news_item['text'] ?>
    </div>
    <p><a href="news/<?php echo $news_item['slug'] ?>">View article</a></p>

<?php endforeach ?>

view.php 在视图中

<?php
echo '<h2>'.$news_item['title'].'</h2>';
echo $news_item['text'];

【问题讨论】:

  • 检查新闻控制器中是否存在名为Agung的函数

标签: php codeigniter web frameworks


【解决方案1】:

你还没有完成tutorial末尾的“路由”部分。

另外,不要从 CodeIgniter 2.x 开始学习 - 它不再受支持 - 改用第 3 版。

【讨论】:

    猜你喜欢
    • 2012-08-18
    • 2017-03-07
    • 1970-01-01
    • 2017-11-16
    • 1970-01-01
    • 2018-04-18
    • 1970-01-01
    • 2018-04-18
    • 2016-01-12
    相关资源
    最近更新 更多