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();
}
}
?>
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();
}
}
?>
No Comment to " Memanggil Model Lebih dari Satu pada CodeIgniter "
Post a Comment