summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/general/models.rst
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-11-09 16:25:00 +0100
committerAndrey Andreev <narf@bofh.bg>2012-11-09 16:25:00 +0100
commit16a704ce8a1449cbee22fb13bd32508c975fac9f (patch)
tree524dbee290643a7dc762ddc505a0216bc871a6ef /user_guide_src/source/general/models.rst
parent1bc30260d8bd35a958f3d7b899f68c95d69c9e75 (diff)
[ci skip] Polish docs in user_guide_src/source/general/
Diffstat (limited to 'user_guide_src/source/general/models.rst')
-rw-r--r--user_guide_src/source/general/models.rst97
1 files changed, 48 insertions, 49 deletions
diff --git a/user_guide_src/source/general/models.rst b/user_guide_src/source/general/models.rst
index 4e52a9648..a028a9569 100644
--- a/user_guide_src/source/general/models.rst
+++ b/user_guide_src/source/general/models.rst
@@ -18,55 +18,56 @@ model class might look like::
class Blog_model extends CI_Model {
- public $title = '';
- public $content = '';
- public $date = '';
-
- function __construct()
- {
- // Call the Model constructor
- parent::__construct();
- }
-
- function get_last_ten_entries()
- {
- $query = $this->db->get('entries', 10);
- return $query->result();
- }
-
- function insert_entry()
- {
- $this->title = $_POST['title']; // please read the below note
- $this->content = $_POST['content'];
- $this->date = time();
-
- $this->db->insert('entries', $this);
- }
-
- function update_entry()
- {
- $this->title = $_POST['title'];
- $this->content = $_POST['content'];
- $this->date = time();
-
- $this->db->update('entries', $this, array('id' => $_POST['id']));
- }
+ public $title;
+ public $content;
+ public $date;
+
+ public function __construct()
+ {
+ // Call the CI_Model constructor
+ parent::__construct();
+ }
+
+ public function get_last_ten_entries()
+ {
+ $query = $this->db->get('entries', 10);
+ return $query->result();
+ }
+
+ public function insert_entry()
+ {
+ $this->title = $_POST['title']; // please read the below note
+ $this->content = $_POST['content'];
+ $this->date = time();
+
+ $this->db->insert('entries', $this);
+ }
+
+ public function update_entry()
+ {
+ $this->title = $_POST['title'];
+ $this->content = $_POST['content'];
+ $this->date = time();
+
+ $this->db->update('entries', $this, array('id' => $_POST['id']));
+ }
}
-.. note:: The functions in the above example use the :doc:`Active
- Record <../database/query_builder>` database functions.
+.. note:: The methods in the above example use the :doc:`Query Builder
+ <../database/query_builder>` database methods.
-.. note:: For the sake of simplicity in this example we're using $_POST
+.. note:: For the sake of simplicity in this example we're using ``$_POST``
directly. This is generally bad practice, and a more common approach
- would be to use the :doc:`Input Class <../libraries/input>`
- $this->input->post('title')
+ would be to use the :doc:`Input Library <../libraries/input>`
+ ``$this->input->post('title')``.
Anatomy of a Model
==================
-Model classes are stored in your **application/models/ folder**. They can be
-nested within sub-folders if you want this type of organization.
+Model classes are stored in your **application/models/** directory.
+They can be nested within sub-directories if you want this type of
+organization.
The basic prototype for a model class is this::
@@ -103,14 +104,14 @@ Loading a Model
===============
Your models will typically be loaded and called from within your
-:doc:`controller <controllers>` functions. To load a model you will use
+:doc:`controller <controllers>` methods. To load a model you will use
the following method::
$this->load->model('model_name');
-If your model is located in a sub-folder, include the relative path from
-your models folder. For example, if you have a model located at
-application/models/blog/queries.php you'll load it using::
+If your model is located in a sub-directory, include the relative path
+from your models directory. For example, if you have a model located at
+*application/models/blog/queries.php* you'll load it using::
$this->load->model('blog/queries');
@@ -141,7 +142,6 @@ view::
$this->load->view('blog', $data);
}
-
}
@@ -163,10 +163,9 @@ database. The following options for connecting are available to you:
- You can connect using the standard database methods :doc:`described
here <../database/connecting>`, either from within your
Controller class or your Model class.
-- You can tell the model loading function to auto-connect by passing
- TRUE (boolean) via the third parameter, and connectivity settings, as
- defined in your database config file will be used:
- ::
+- You can tell the model loading method to auto-connect by passing
+ TRUE (boolean) via the third parameter, and connectivity settings,
+ as defined in your database config file will be used::
$this->load->model('model_name', '', TRUE);