[eluser]Unknown[/eluser]
.htaccess
Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
</IfModule>
routes.php
Code:
$route['default_controller'] = "web";
$route['404_override'] = '';
$route['(:any)'] = 'web/$1';
web.php (controller)
Code:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Web extends CI_Controller{
public function __construct()
{
parent::__construct();
// Your own construct code
$this->load->model('Users_model');
$this->load->model('News_model');
$this->load->database('mitra');
}
// ini untuk setting halaman utama
function index(){
$this->load->model('news_model');
$data['news'] = $this->news_model->get_news();
$this->load->model('content_model');
$data['query'] = $this->content_model->get_home();
$this->load->view('home_view', $data);
}
news_model.php
Code:
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();
}
function viewnews($slug)
{
$this->load->model('news_model');
$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('news_view', $data);
}
view
Code:
<h2 class="beritaterbaru">Berita terbaru :</h2>
<ul class="listberitadepan">
<?php foreach($news as $news_item): ?>
<li>
<h2 class="tanggalberita"><?php echo $news_item['date']?></h2>
<h2 class="judulberitadepan"><a href="<?php echo $news_item['slug'] ?>"><?php echo $news_item['title']?></a></h2>
<p><?php echo $news_item['intro'] ?></p>
</li>
<?php endforeach ?>
</ul>
the problem is, when i clik news doesnt work, didnt show, and i thing the problem is routes, because my default controller is web, and didnt work. Exam:
http://localhost/mitra/about.html ( work, the data it show )
and when news,
http://localhost/mitra/pembukaan.kantor.cabang.pembantu ( didnt show the data )
but when i change my routes to :
$route['default_controller'] = "web";
$route['404_override'] = '';
$route['(:any)'] = 'web/viewnews/$1';
data for may news it showing, but the other
http://localhost/mitra/about.html dosnt show the data,
please help me.. tq