H
H
HeartOfProgrammer2015-11-16 22:00:52
CodeIgniter
HeartOfProgrammer, 2015-11-16 22:00:52

Why is it not outputting data to codeigniter?

The problem is that codeigniter does not display data from the database,
in my controller it is written like this:

function index()
  {
    $this->load->view('header_view');
    $this->load->view('main_view');
    $this->load->view('footer_view');
  }

My view: main_view
<!DOCTYPE html>
<html lang="ru">
<head>
  <meta charset="UTF-8">
  <title>Главная страница</title>
</head>
<body>
  <div class="container">
    <div class="item_news">
          <?php foreach($articles as $item):?>
        <p><?=$item['title']?></p>
        <p><?=$item['text']?></p>
        <p><?=$item['date']?></p>
      <?endforeach;?>
      <?=$this->pagination->create_links();?>
    </div>
  </div>
</body>
</html>

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

class Articles_model extends CI_Model {
  function get_articles($num, $offset)
  {
    $this->db->order_by('id', 'desk');
    $query = $this->db->get('articles', $num, $offset);
    return $query->result_array();
  }

  function add_article($data)
  {
    $this->db->insert('articles',$data);
  }

  function edit_article($data)
  {
    $this->db->where('id', '5');
    $this->db->update('articles',$data);
  }

  function delete_article($id)
  {
    $this->db->where('id',$id);
    $this->db->delete('articles');
  }
}

Errors shown by codeigniter:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: articles
Filename: views/main_view.php
Line Number: 10
Backtrace:
File: D:\OpenServer\domains\localhost\codeigniter\application\views\main_view.php
Line: 10
Function: _error_handler
File: D:\OpenServer\domains\localhost\codeigniter\application\controllers\main.php
Line: 9
Function: view
File: D:\OpenServer\domains\localhost\codeigniter\index.php
Line: 292
Function: require_once

PS I'm confused about this framework, just started learning it. Do not judge strictly, just tell me where my mistake is.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
best_santa, 2015-11-16
@HeartOfProgrammer

function index()
  {
// Подгружаешь модель
$this->load->model('articles_model');
// выбираешь артикли, сколько тебе нужно
$this->data['articles'] = $this->articles_model->get_articles(10, 0);

    $this->load->view('header_view');
    $this->load->view('main_view');
    $this->load->view('footer_view');
  }

It is written: "Message: Undefined variable: articles".

A
Anar4you, 2015-11-16
@Anar4you

Dmitry Valak's guides are not very good(

E
Evgeny Lavrentiev, 2015-11-17
@lavrentiev

Throw it away, don't waste your time Yii or Lara in favor )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question