Welcome Guest, Not a member yet? Register   Sign In
route for controller with default for setting
#1

[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:
&lt;?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">
&lt;?php foreach($news as $news_item): ?&gt;
<li>
<h2 class="tanggalberita">&lt;?php echo $news_item['date']?&gt;</h2>
<h2 class="judulberitadepan"><a href="&lt;?php echo $news_item['slug'] ?&gt;">&lt;?php echo $news_item['title']?&gt;</a></h2>
<p>&lt;?php echo $news_item['intro'] ?&gt;</p>
</li>

&lt;?php endforeach ?&gt;
</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




Theme © iAndrew 2016 - Forum software by © MyBB