summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/general/models.rst
diff options
context:
space:
mode:
Diffstat (limited to 'user_guide_src/source/general/models.rst')
-rw-r--r--user_guide_src/source/general/models.rst75
1 files changed, 38 insertions, 37 deletions
diff --git a/user_guide_src/source/general/models.rst b/user_guide_src/source/general/models.rst
index 0156b0460..4e52a9648 100644
--- a/user_guide_src/source/general/models.rst
+++ b/user_guide_src/source/general/models.rst
@@ -16,11 +16,11 @@ blog. You might have a model class that contains functions to insert,
update, and retrieve your blog data. Here is an example of what such a
model class might look like::
- class Blogmodel extends CI_Model {
+ class Blog_model extends CI_Model {
- var $title = '';
- var $content = '';
- var $date = '';
+ public $title = '';
+ public $content = '';
+ public $date = '';
function __construct()
{
@@ -72,10 +72,11 @@ The basic prototype for a model class is this::
class Model_name extends CI_Model {
- function __construct()
- {
- parent::__construct();
- }
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
}
Where **Model_name** is the name of your class. Class names **must** have
@@ -87,10 +88,11 @@ example, if your class is this::
class User_model extends CI_Model {
- function __construct()
- {
- parent::__construct();
- }
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
}
Your file will be this::
@@ -102,9 +104,9 @@ 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
-the following function::
+the following method::
- $this->load->model('Model_name');
+ $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
@@ -112,33 +114,34 @@ application/models/blog/queries.php you'll load it using::
$this->load->model('blog/queries');
-Once loaded, you will access your model functions using an object with
-the same name as your class::
+Once loaded, you will access your model methods using an object with the
+same name as your class::
- $this->load->model('Model_name');
+ $this->load->model('model_name');
- $this->Model_name->function();
+ $this->model_name->method();
If you would like your model assigned to a different object name you can
-specify it via the second parameter of the loading function::
+specify it via the second parameter of the loading method::
- $this->load->model('Model_name', 'fubar');
+ $this->load->model('model_name', 'foobar');
- $this->fubar->function();
+ $this->foobar->method();
Here is an example of a controller, that loads a model, then serves a
view::
class Blog_controller extends CI_Controller {
- function blog()
- {
- $this->load->model('Blog');
+ public function blog()
+ {
+ $this->load->model('blog');
- $data['query'] = $this->Blog->get_last_ten_entries();
+ $data['query'] = $this->Blog->get_last_ten_entries();
+
+ $this->load->view('blog', $data);
+ }
- $this->load->view('blog', $data);
- }
}
@@ -165,20 +168,18 @@ database. The following options for connecting are available to you:
defined in your database config file will be used:
::
- $this->load->model('Model_name', '', TRUE);
+ $this->load->model('model_name', '', TRUE);
- You can manually pass database connectivity settings via the third
parameter::
- $config['hostname'] = "localhost";
- $config['username'] = "myusername";
- $config['password'] = "mypassword";
- $config['database'] = "mydatabase";
- $config['dbdriver'] = "mysql";
- $config['dbprefix'] = "";
+ $config['hostname'] = 'localhost';
+ $config['username'] = 'myusername';
+ $config['password'] = 'mypassword';
+ $config['database'] = 'mydatabase';
+ $config['dbdriver'] = 'mysqli';
+ $config['dbprefix'] = '';
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
- $this->load->model('Model_name', '', $config);
-
-
+ $this->load->model('Model_name', '', $config); \ No newline at end of file