Answer the question
In order to leave comments, you need to log in
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');
}
<!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>
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');
}
}
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
Answer the question
In order to leave comments, you need to log in
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');
}
Throw it away, don't waste your time Yii or Lara in favor )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question