Ссылки codeigniter ошибка 404 Page Not Found

0

Столкнулся с такой проблемой, что когда я перехожу в просмотр новости мне отображается ошибка

404 Page Not Found
The page you requested was not found.

Код 

1) Route

//$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

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

2) Controller 

<?php 

defined('BASEPATH') OR exit('No direct script access allowed');

class News extends CI_Controller {

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

    public function index() {
        $data['title'] = "Все новости";
        $data['news'] = $this->model->getNews();

        $this->load->view('templates/header', $data);
        $this->load->view('news/index', $data);
        $this->load->view('templates/footer');
    }

    public function view($slug = NULL) {
        $data['news_stuff'] = $this->model->getNews($slug);

        if (empty($data['news_stuff'])) {
            show_404();
        }

        $data['title'] = $data['news_stuff']['title'];
        $data['content'] = $data['news_stuff']['text'];

        $this->load->view('templates/header', $data);
        $this->load->view('news/view', $data);
        $this->load->view('templates/footer');
    }
}

3) Model

<?php

class Model extends CI_Model {

    public function __construct() {
        $this->load->database();
    }

    public function getNews($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();
    }
}

4) index.php

<h2> <?php echo $title; ?> </h2>
<?php foreach ($news as $key => $value): ?>
    <a href="view/<?php echo $value['slug']; ?>"><?php echo $value['title']; ?></a> 
<?php endforeach ?>

5) view.php

<?php echo $title; ?>
<?php echo $content; ?>

Базу данных связал с фреймворком

 

codeigniter

2 ответов

2

в браузере:

http://techaven.com/index.php/news/view/%D0%9D%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D1%8C%201%20testSlug

в sublime

<a href="view/<?php echo $value['slug']; ?>"><?php echo $value['title']; ?></a>
1

Ссылки как выглядят, которые не работают?

Sign up or Log in to write an answer