From 697b75e5296c4add2577db9099c235781fd34430 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:22:58 +0100 Subject: Changed example model name to follow the CI styleguide class naming conventions --- user_guide_src/source/general/models.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'user_guide_src/source/general/models.rst') diff --git a/user_guide_src/source/general/models.rst b/user_guide_src/source/general/models.rst index 0156b0460..72acf77b4 100644 --- a/user_guide_src/source/general/models.rst +++ b/user_guide_src/source/general/models.rst @@ -16,7 +16,7 @@ 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 = ''; -- cgit v1.2.3-24-g4f1b From 149c07726bb60df65766a1046e695b1897652cc7 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:23:41 +0100 Subject: Changed load model examples to use lowercase model name. Fixes #1417 --- user_guide_src/source/general/models.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'user_guide_src/source/general/models.rst') diff --git a/user_guide_src/source/general/models.rst b/user_guide_src/source/general/models.rst index 72acf77b4..87f63e416 100644 --- a/user_guide_src/source/general/models.rst +++ b/user_guide_src/source/general/models.rst @@ -104,7 +104,7 @@ Your models will typically be loaded and called from within your :doc:`controller ` functions. To load a model you will use the following function:: - $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 @@ -115,14 +115,14 @@ application/models/blog/queries.php you'll load it using:: Once loaded, you will access your model functions 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->function(); If you would like your model assigned to a different object name you can specify it via the second parameter of the loading function:: - $this->load->model('Model_name', 'fubar'); + $this->load->model('model_name', 'fubar'); $this->fubar->function(); @@ -133,7 +133,7 @@ view:: function blog() { - $this->load->model('Blog'); + $this->load->model('blog'); $data['query'] = $this->Blog->get_last_ten_entries(); @@ -165,7 +165,7 @@ 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:: -- cgit v1.2.3-24-g4f1b From ff3f7dea40e8fae81dd586b340d30d24154cf5ab Mon Sep 17 00:00:00 2001 From: vlakoff Date: Sat, 16 Jun 2012 14:21:32 +0200 Subject: Documentation: remaining PHP "var" declarations changed to "public" Since PHP 4 isn't supported anymore, let's clean up these few PHP "var" declarations which were remaining in the documentation. According to my checks, there is no more PHP "var" left. --- user_guide_src/source/general/models.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'user_guide_src/source/general/models.rst') diff --git a/user_guide_src/source/general/models.rst b/user_guide_src/source/general/models.rst index 87f63e416..2e1e025ee 100644 --- a/user_guide_src/source/general/models.rst +++ b/user_guide_src/source/general/models.rst @@ -18,9 +18,9 @@ model class might look like:: class Blog_model extends CI_Model { - var $title = ''; - var $content = ''; - var $date = ''; + public $title = ''; + public $content = ''; + public $date = ''; function __construct() { -- cgit v1.2.3-24-g4f1b From b94b91afc77bcc133ff282559015933602bb2d3f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 4 Jul 2012 12:32:14 +0300 Subject: Some user guide updates --- user_guide_src/source/general/models.rst | 61 ++++++++++++++++---------------- 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'user_guide_src/source/general/models.rst') diff --git a/user_guide_src/source/general/models.rst b/user_guide_src/source/general/models.rst index 2e1e025ee..4e52a9648 100644 --- a/user_guide_src/source/general/models.rst +++ b/user_guide_src/source/general/models.rst @@ -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,7 +104,7 @@ Loading a Model Your models will typically be loaded and called from within your :doc:`controller ` functions. To load a model you will use -the following function:: +the following method:: $this->load->model('model_name'); @@ -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->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); - } } @@ -170,15 +173,13 @@ database. The following options for connecting are available to you: - 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 -- cgit v1.2.3-24-g4f1b