ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

News Section data not showing | database connection

August 21, 2014 2:51am

Subscribe [3]
  • #1 / Aug 21, 2014 2:51am

    DaveSonar

    1 posts

    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 : 

    <a href="https://ellislab.com/codeigniter/user-guide/tutorial/news_section.html">https://ellislab.com/codeigniter/user-guide/tutorial/news_section.html</a>

    it’s appeared nothing in

    http://localhost/CodeIgniter_2.2.0/index.php/news

    These are the pages :

    news_model.php locate in \Application\model

    <?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

    <?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

    $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

    $autoload['libraries'] = array('database');

    using XAMPP - phpmyadmin and database created with given query .

    config\database.php

    $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 😊

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

    and it’s successfully done

     

  • #2 / Aug 21, 2014 3:39am

    naminator

    1 posts

    I’ve found the same problem too.

  • #3 / Aug 21, 2014 8:56am

    InsiteFX

    6819 posts

    It is because you are not following the instructions!

    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 / Aug 21, 2014 5:13pm

    DaveSonar

    1 posts

    It is because you are not following the instructions!

    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.


    Thanks found it 😊
    i

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases