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