Skip to content

Commit 73221b2

Browse files
committed
Merge branch 'mininix-patch'
- [x] Translate 'general/models.rst'
2 parents 3749903 + 6c3e2d6 commit 73221b2

File tree

1 file changed

+83
-91
lines changed

1 file changed

+83
-91
lines changed

source/general/models.rst

Lines changed: 83 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,74 @@
1-
######
2-
Models
3-
######
1+
#####
2+
Model
3+
#####
44

5-
Models are **optionally** available for those who want to use a more
6-
traditional MVC approach.
5+
Models merupakan suatu *opsi* yang tersedia untuk siapa saja yang ingin menggunakan pendekatan tradisional yang lebih pada MVC.
76

8-
.. contents:: Page Contents
7+
.. contents:: Daftar Isi
98

10-
What is a Model?
11-
================
9+
Apa itu model?
10+
==============
1211

13-
Models are PHP classes that are designed to work with information in
14-
your database. For example, let's say you use CodeIgniter to manage a
15-
blog. You might have a model class that contains functions to insert,
16-
update, and retrieve your blog data. Here is an example of what such a
17-
model class might look like::
12+
Model merupakan class PHP yang didesain untuk hal-hal yang terkait dengan informasi basis data.
13+
Sebagai contoh, katakanlah Anda menggunakan CodeIgniter untuk mengolah sebuah blog.
14+
Anda mesti memiliki sebuah class model yang berisi beberapa fungsi (metode) untuk menambah, mengedit, atau menampilkan data blog Anda.
15+
Berikut ini sebuah contoh seperti apa yang dimaksud dengan class model::
1816

1917
class Blog_model extends CI_Model {
2018

21-
public $title;
22-
public $content;
23-
public $date;
19+
public $judul;
20+
public $konten;
21+
public $waktu;
2422

2523
public function __construct()
2624
{
27-
// Call the CI_Model constructor
25+
// Memanggil konstruktor CI_Model
2826
parent::__construct();
2927
}
3028

31-
public function get_last_ten_entries()
29+
public function data_sepuluh_artikel_terakhir()
3230
{
33-
$query = $this->db->get('entries', 10);
31+
$query = $this->db->get('artikel', 10);
3432
return $query->result();
3533
}
3634

37-
public function insert_entry()
35+
public function tambahkan_item()
3836
{
39-
$this->title = $_POST['title']; // please read the below note
40-
$this->content = $_POST['content'];
41-
$this->date = time();
37+
$this->judul = $_POST['judul']; // lihat catatan di bawah
38+
$this->konten = $_POST['konten'];
39+
$this->waktu = time();
4240

43-
$this->db->insert('entries', $this);
41+
$this->db->insert('artikel', $this);
4442
}
4543

46-
public function update_entry()
44+
public function sunting_artikel()
4745
{
48-
$this->title = $_POST['title'];
49-
$this->content = $_POST['content'];
50-
$this->date = time();
46+
$this->judul = $_POST['judul'];
47+
$this->konten = $_POST['konten'];
48+
$this->waktu = time();
5149

52-
$this->db->update('entries', $this, array('id' => $_POST['id']));
50+
$this->db->update('artikel', $this, array('id' => $_POST['id']));
5351
}
5452

5553
}
5654

57-
.. note:: The methods in the above example use the :doc:`Query Builder
58-
<../database/query_builder>` database methods.
55+
.. note:: Beberapa metode atau fungsi pada contoh di atas menggunakan metode basis data yang dinamakan :doc:`Query Builder
56+
<../database/query_builder>`.
5957

60-
.. note:: For the sake of simplicity in this example we're using ``$_POST``
61-
directly. This is generally bad practice, and a more common approach
62-
would be to use the :doc:`Input Library <../libraries/input>`
63-
``$this->input->post('title')``.
58+
.. note:: Untuk contoh sederhana di sini menggunakan ``$_POST`` secara langsung.
59+
Umumnya ini praktek yang buruk untuk dilakukan, mengingat akan timbulnya masalah celah keamanan.
60+
Untuk pendekatan yang lebih baik, sebaiknya menggunakan :doc:`Input Library <../libraries/input>`
61+
``$this->input->post('judul')`` dan sebagainya.
6462

65-
Anatomy of a Model
66-
==================
63+
Susunan sebuah Model
64+
====================
6765

68-
Model classes are stored in your **application/models/** directory.
69-
They can be nested within sub-directories if you want this type of
70-
organization.
66+
Berkas atau class model berada di direktori **application/models/**.
67+
Model dapat dikelompokkan di dalam sub-direktori bila model yang Anda inginkan menjadi lebih terorganisir.
7168

72-
The basic prototype for a model class is this::
69+
Bentuk dasar sebuah model digambarkan seperti berikut ini::
7370

74-
class Model_name extends CI_Model {
71+
class Nama_model extends CI_Model {
7572

7673
public function __construct()
7774
{
@@ -80,11 +77,11 @@ The basic prototype for a model class is this::
8077

8178
}
8279

83-
Where **Model_name** is the name of your class. Class names **must** have
84-
the first letter capitalized with the rest of the name lowercase. Make
85-
sure your class extends the base Model class.
80+
Dimana **Nama_model** adalah nama class dari class model yang Anda buat.
81+
Penamaan class **harus** dimulai dengan huruf besar (kapital) pada karakter huruf pertama.
82+
Pastikan model class Anda merupakan turunan dari base Model (class **CI_Model** atau **MY_Model**).
8683

87-
The file name must match the class name. For example, if this is your class::
84+
Antara nama berkas dan nama class harus sama. Sebagai contoh, jika Anda menggunakan model class berikut::
8885

8986
class User_model extends CI_Model {
9087

@@ -95,89 +92,84 @@ The file name must match the class name. For example, if this is your class::
9592

9693
}
9794

98-
Your file will be this::
95+
Maka, nama berkasnya harus seperti ini::
9996

10097
application/models/User_model.php
10198

102-
Loading a Model
103-
===============
99+
Menghubungkan sebuah Model
100+
==========================
104101

105-
Your models will typically be loaded and called from within your
106-
:doc:`controller <controllers>` methods. To load a model you will use
107-
the following method::
102+
Model pada dasarnya akan dimuat dan dipanggil dari metode atau fungsi yang ada pada
103+
:doc:`controller <controllers>`. Untuk menghubungkan model, Anda harus menggunakan metode berikut ini::
108104

109-
$this->load->model('model_name');
105+
$this->load->model('nama_model');
110106

111-
If your model is located in a sub-directory, include the relative path
112-
from your models directory. For example, if you have a model located at
113-
*application/models/blog/Queries.php* you'll load it using::
107+
Jika model yang Anda buat terletak di dalam sebuah sub-direktori, sertakan alamat relatif (*relative path*) dari model yang Anda buat.
108+
Sebagai contoh, jika model yang Anda miliki berlokasi di
109+
*application/models/blog/Queries.php* Anda akan menghubungkannya dengan cara::
114110

115111
$this->load->model('blog/queries');
116112

117-
Once loaded, you will access your model methods using an object with the
118-
same name as your class::
113+
Ketika terhubung, Anda dapat mengakses metode-metode yang ada pada model menggunakan sebuah objek
114+
dengan nama yang sama dengan nama model class yang Anda buat sebelumnya::
119115

120-
$this->load->model('model_name');
116+
$this->load->model('nama_model');
121117

122-
$this->model_name->method();
118+
$this->nama_model->metode();
123119

124-
If you would like your model assigned to a different object name you can
125-
specify it via the second parameter of the loading method::
120+
Jika Anda ingin menggunakan objek yang berbeda untuk sebuah model, Anda bisa menggunakan penamaan (alias) di parameter kedua::
126121

127-
$this->load->model('model_name', 'foobar');
122+
$this->load->model('nama_model', 'foobar');
128123

129-
$this->foobar->method();
124+
$this->foobar->metode();
130125

131-
Here is an example of a controller, that loads a model, then serves a
132-
view::
126+
Berikut adalah contoh sebuah controller yang terhubung dengan sebuah model
127+
dan menampilkan data hasil olahan model ke view::
133128

134129
class Blog_controller extends CI_Controller {
135130

136131
public function blog()
137132
{
138133
$this->load->model('blog');
139134

140-
$data['query'] = $this->blog->get_last_ten_entries();
135+
$data['query'] = $this->blog->data_sepuluh_artikel_terakhir();
141136

142137
$this->load->view('blog', $data);
143138
}
144139
}
145140
146141

147-
Auto-loading Models
148-
===================
142+
*Auto-loading* Model
143+
====================
149144

150-
If you find that you need a particular model globally throughout your
151-
application, you can tell CodeIgniter to auto-load it during system
152-
initialization. This is done by opening the
153-
**application/config/autoload.php** file and adding the model to the
154-
autoload array.
145+
Auto-loading (menghubungkan secara otomatis) model tertentu secara global bisa Anda lakukan dengan
146+
menggunakan pengaturan yang ada pada berkas **application/config/autoload.php**. Tambahkan model yang
147+
ingin Anda hubungkan secara otomatis selama sistem berjalan::
155148

156-
Connecting to your Database
157-
===========================
149+
$autoload['model'] = array('nama_model');
158150

159-
When a model is loaded it does **NOT** connect automatically to your
160-
database. The following options for connecting are available to you:
151+
Koneksi ke Basis Data (Database)
152+
================================
161153

162-
- You can connect using the standard database methods :doc:`described
163-
here <../database/connecting>`, either from within your
164-
Controller class or your Model class.
165-
- You can tell the model loading method to auto-connect by passing
166-
TRUE (boolean) via the third parameter, and connectivity settings,
167-
as defined in your database config file will be used::
154+
Ketika sebuah model sudah terhubung namun tidak dapat terkoneksi ke basis data secara otomatis,
155+
beberapa opsi yang bisa digunakan untuk mengatasi masalah ini:
168156

169-
$this->load->model('model_name', '', TRUE);
157+
- Anda dapat meng-koneksikan dengan menggunakan standar metode database (:doc:`penjelasan di sini <../database/connecting>`),
158+
antara class Controller atau class Model.
159+
- Anda dapat mengatur sebuah model melakukan *auto-connect* dengan menambahkan nilai TRUE (boolean) di parameter ketiga.
160+
Atau mengatur konektivitas sebagaimana yang telah didefinisikan di dalam berkas **application/config/database.php**::
170161

171-
- You can manually pass database connectivity settings via the third
172-
parameter::
162+
$this->load->model('nama_model', '', TRUE);
163+
164+
- Anda dapat mengatur koneksi secara manual dengan menambahkan item-item berupa array pada parameter ketiga seperti contoh berikut::
173165

174166
$config['hostname'] = 'localhost';
175-
$config['username'] = 'myusername';
176-
$config['password'] = 'mypassword';
177-
$config['database'] = 'mydatabase';
167+
$config['username'] = 'namapengguna';
168+
$config['password'] = 'katasandi';
169+
$config['database'] = 'nama_database';
178170
$config['dbdriver'] = 'mysqli';
179171
$config['dbprefix'] = '';
180172
$config['pconnect'] = FALSE;
181173
$config['db_debug'] = TRUE;
182174

183-
$this->load->model('model_name', '', $config);
175+
$this->load->model('nama_model', '', $config);

0 commit comments

Comments
 (0)