By Martin Tobing → Tuesday, December 2, 2014
Untuk memanggil model lebih dari satu pada CodeIgniter, bisa menggunakan array. Berikut ini contoh penggunaannya :
File Controller : (/application/controller/test.php):
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Test extends CI_Controller {
public function index()
{
// List of Models
$models = array(
'user_model' => 'user',
'main_model' => 'main',
'my_model' => 'my',
);
// Load Multiple Models
foreach ($models as $file => $object_name)
{
$this->load->model($file, $object_name);
}
// Panggil model "my_model"
echo $this->my->get_last_query();
// Panggil model "user_model"
echo $this->user->get_something();
// Panggil model "main_model"
echo $this->main->view_something();
}
}
?>
Martin Tobing

I'm Martin Tobing. A full time web programmer. I enjoy to make website and web application in PHP.

No Comment to " Memanggil Model Lebih dari Satu pada CodeIgniter "