D
D
Dmitry2021-06-24 10:32:41
CodeIgniter
Dmitry, 2021-06-24 10:32:41

Why doesn't Codeignater 3 post page display work?

Good day. I'm doing a test task, but there was a problem that I can not overcome. When passing by reference to the model through the controller, the slug record is not transferred.
Here is the controller file:

public function show($slug = NULL) {
    $data['news_item'] = $this->news_model->getSingleNews($slug);

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

    $data['slug'] = $slug;

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

Model file:
public function getSingleNews($slug) {
    $query = $this->db->get_where('news', array('slug' => $slug));
    return $query->row_array();
  }

Here is the routing: This link takes us from the loop to the post page:
$route['news/article/(:any)'] = 'news/show/$1';
<a href="/news/article/<?php echo $news_item['slug']; ?>">More...</a>
. I will be grateful for any help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question