Akhirnya dengan berat hati akhirnya memakai jalan pintas
Yah minimal bisa tampil di halaman browser (._.")
Okey, here it is :)
1. Setting Config
Yang perlu dirubah dari file config ini hanyalah bagian-bagian di bawah ini:
$config['base_url'] = 'http://localhost/d4b6/';
2. Setting autoload
Ubah pada bagian di bawah ini
$autoload['libraries'] = array('database', 'session');
$autoload['helper'] = array('url','file');
3. Add file baru pada directory controller
<?php if ( ! defined('BASEPATH'))
exit('No direct script access allowed');
class News extends CI_Controller {
public
function index()
{
$data
= array('title' => 'Test Title',
'heading'
=> 'Test Heading',
'message'
=> 'Test Message');
$this->load->view('view_header');
$this->load->view('view_news_show',
$data);
$this->load->view('view_footer');
}
public
function show(){
$data['n'] =
$this->ModelNews->getAllNews();
$this->load->view('news/view_show_page', $data);
}
}
4. File-file pada directory views
- Buat
header
testing <br />
- Buat
footer
testing <br />
- View_news_show
<!DOCTYPE html>
<html lang="en">
<head>
<title> <?=$title;?> </title>
</head>
<body>
<h2> <?php echo $heading; ?> </h2>
<p> <? echo $message; ?>
</p>
</body>
</html>
- View_show_page dalam folder news
<?
print_r($n);
$sr = $n->result();
?>
<p>List News</p>
<? foreach($sr as $r){ ?>
<?=$r->id?> <br
/>
<?=$r->title?>
<br />
<?=$r->content?> <br />
<?=$r->create?> <br /><br />
<? } ?>
5 5. Tambahkan file baru (ModelNews) pada
directory models
<?php if ( ! defined('BASEPATH'))
exit('No direct script access allowed');
class ModelNews extends CI_Model {
function __construct()
{
parent::__construct();
}
function
getAllNews(){
$q="SELECT
* FROM news";
return
$this->db->query($q);
}
}
7. Terakhir check database untuk diaktifkan
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'db_d4b6'; // sesuai nama database
yang dibuat
$db['default']['dbdriver'] = 'mysql';
$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;
Hasil Konfigurasi
Dan sepertinya kesalahan saya kemarin harus beres hari ini.. Fightoo :")
Tidak ada komentar:
Posting Komentar