Welcome Guest, Not a member yet? Register   Sign In
News Section data not showing | database connection
#1

[eluser]Unknown[/eluser]
Hi ,
I'm new to the CI and currently following the user guide .
followed the static page create section and now when i followed this :

Code:
https://ellislab.com/codeigniter/user-guide/tutorial/news_section.html

it's appeared nothing in
Quote:http://localhost/CodeIgniter_2.2.0/index.php/news

These are the pages :

news_model.php locate in \Application\model
Code:
<?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();
}
}

in controllers : news.php

Code:
<?php
class News extends CI_Controller {

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

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

        
       public function view($slug)
{
$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');
}
}

in config\routes.php

Code:
$route['default_controller'] = "welcome";
$route['404_override'] = '';

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

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

also i set the autoload.php to
Code:
$autoload['libraries'] = array('database');

using XAMPP - phpmyadmin and database created with given query .

config\database.php
Code:
$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '123';
$db['default']['database'] = 'sl2cpf';
$db['default']['dbdriver'] = 'mysqli';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

glad if anyone can help with this Smile

PS : followed Create News :https://ellislab.com/codeigniter/user-guide/tutorial/create_news_items.html

and it's successfully done

#2

[eluser]Unknown[/eluser]
I've found the same problem too.
#3

[eluser]InsiteFX[/eluser]
It is because you are not following the instructions!

Code:
public function index()
{
$data['news'] = $this->news_model->get_news();
$data['title'] = 'News archive';

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

Read the User Guide again all the way and you will see.
#4

[eluser]Unknown[/eluser]
[quote author="InsiteFX" date="1408625778"]It is because you are not following the instructions!

Code:
public function index()
{
$data['news'] = $this->news_model->get_news();
$data['title'] = 'News archive';

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

Read the User Guide again all the way and you will see.
[/quote]


Thanks found it Smile
i




Theme © iAndrew 2016 - Forum software by © MyBB