Why does Codeigniter have a Model class with constructor and get only?

Can someone tell me why Codeigniter has a Model class that is almost bare? What does this project do?

1: <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 2: /**
 3:  * CodeIgniter
 4:  *
 5:  * An open source application development framework for PHP 5.1.6 or newer
 6:  *
 7:  * @package     CodeIgniter
 8:  * @author      ExpressionEngine Dev Team
 9:  * @copyright   Copyright (c) 2008 - 2011, EllisLab, Inc.
10:  * @license     http://codeigniter.com/user_guide/license.html
11:  * @link        http://codeigniter.com
12:  * @since       Version 1.0
13:  * @filesource
14:  */
15: 
16: // ------------------------------------------------------------------------
17: 
18: /**
19:  * CodeIgniter Model Class
20:  *
21:  * @package     CodeIgniter
22:  * @subpackage  Libraries
23:  * @category    Libraries
24:  * @author      ExpressionEngine Dev Team
25:  * @link        http://codeigniter.com/user_guide/libraries/config.html
26:  */
27: class CI_Model {
28: 
29:     /**
30:      * Constructor
31:      *
32:      * @access public
33:      */
34:     function __construct()
35:     {
36:         log_message('debug', "Model Class Initialized");
37:     }
38: 
39:     /**
40:      * __get
41:      *
42:      * Allows models to access CI loaded classes using the same
43:      * syntax as controllers.
44:      *
45:      * @param   string
46:      * @access private
47:      */
48:     function __get($key)
49:     {
50:         $CI =& get_instance();
51:         return $CI->$key;
52:     }
53: }
54: // END Model Class
55: 
56: /* End of file Model.php */
57: /* Location: ./system/core/Model.php */

I see the __get function, but I'm not sure what I am doing to help me. How will extending this class help my design?

39:     /**
40:      * __get
41:      *
42:      * Allows models to access CI loaded classes using the same
43:      * syntax as controllers.
44:      *
45:      * @param   string
46:      * @access private
47:      */
48:     function __get($key)
49:     {
50:         $CI =& get_instance();
51:         return $CI->$key;
52:     }
+4
source share
1 answer

Therefore, whenever you extend a class CI_Model, your models inherit functions __constructand __get, both of which are Magic methods ,

A function __constructwill be called whenever you call a function in your model. All he does is just create a log message.

function __construct()
{
    log_message('debug', "Model Class Initialized");
}

, , , - .

$this->load->model('Model_name');
$this->Model_name->function();

, , , - .

__get

.

, CI . , - $this->session->userdata('username'). __get CI_Model, , . , CI_Model, . , ,

+4
source

Source: https://habr.com/ru/post/1532683/


All Articles