aslkm
gan ane newbie nih lg mau cb akses data dr database tp kok error ya.
Tampilan errornya gini gan
A PHP Error was encountered
Severity: Notice
Message: Undefined property: M_helloworld::$db
Filename: models/m_helloworld.php
Line Number: 16
Fatal error: Call to a member function get() on a non-object in C:\xampp\htdocs\HelloWorld\application\models\m_helloworld.php on line 16
c_helloworld.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class C_helloworld extends CI_Controller { function __construct() { parent::__construct(); } function index() { $this->load->model('M_helloworld'); $data['teks'] = $this->M_helloworld->mHello(); $data['siswa'] = $this->M_helloworld->all(); $this->load->view('v_helloworld',$data); } }
M_helloworld.php
<?php class M_helloworld extends CI_Controller { function __construct() { parent::__construct(); } function mHello(){ $teks = "Hello World"; return $teks; } function all() { $this->db->get('maha'); } } ?>
V_helloworld.php
<html> <head> <Title>Testing Hello World</Title> </head> <body> <?php echo $teks; echo '<br>'; ?> <?php foreach($siswa as rows) ?> $rows->nim <?php endforeach ?> </body> </html>
Comments
<?php class M_helloworld
June 7, 2011 by cahndeso, 8 weeks 2 days ago
Comment: 8315
ganti
jangan lupa load library database (masukkan di autoload).
untuk tampilkan data di view
ubah :
menjadi
(baca kembali user_guide/database/active_record.html#select)..
semoga membantu
Happy Coding
Cahndeso