dongying9756 2019-06-05 06:25
浏览 33

如何用codeigniter“新闻”部分解决页面空白问题?

I'm following the Codeigniter tutorial: http://localhost:8080/myproject/user_guide/tutorial/news_section.html

When i point my browser to http://localhost:8080/myproject/news as the tutorial indicates at the final of the section, "Point your browser to your document root, followed by index.php/news and watch your news page." appears a blank page.

I tried to point to localhost:8080/index.php/news or /myproject/news but occurs the same problem.

Also i tried to set in autoload.php the next: $autoload['libraries'] = array('database'); as is indicated in codeigniter news section tutorial not working but not solve, so i leave it like this: $autoload['libraries'] = array('');

This is the routes:

   $route['news/(:any)'] = 'news/view/$1';
   $route['news'] = 'news';
   $route['(:any)'] = 'pages/view/$1';
   $route['default_controller'] = 'pages/view';

The News.php:

   <?php
   class News extends CI_Controller {

    public function __construct()
    {
            parent::__construct();
            $this->load->model('news_model');
            $this->load->helper('url_helper');
    }

    public function index()
    {
            $data['news'] = $this->news_model->get_news();
    }

    public function view($slug = NULL)
   {
    $data['news_item'] = $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');
   }
   }

the view.php:

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

and the 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();
    }
    }

I expect to watch the news page

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 arduino控制ps2手柄一直报错
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥85 maple软件,solve求反函数,出现rootof怎么办?
    • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥20 求一个html代码,有偿