Php 字符串$this->;中的每个单词是什么意思;负载->;codeigniter中的型号(';名称&#U型号';)?

Php 字符串$this->;中的每个单词是什么意思;负载->;codeigniter中的型号(';名称&#U型号';)?,php,codeigniter,Php,Codeigniter,codeigniter中字符串$this->load->model中的每个部分到底是什么意思?在下面的代码中,“$this”引用了用户类(controller)?另外,它是否调用调用模型的方法加载?或者$this是否引用了每个函数的名称 <?php class User extends CI_Controller { function __construct() { parent::__construct(); $this->t

codeigniter中字符串$this->load->model中的每个部分到底是什么意思?在下面的代码中,“$this”引用了用户类(controller)?另外,它是否调用调用模型的方法加载?或者$this是否引用了每个函数的名称

<?php 
class User extends CI_Controller {

    function __construct() 
    {
        parent::__construct(); 
        $this->template->set_layout('adminLayout.php');
        $this->load->model("User_model");
        $this->load->Model('Auth_model'); 
    }


    function index()
    {
        $this->Auth_model->isLoggedIn();
        $this->template->title('Admin ::');
        $this->template->build('admin/index');
    }
?>

$这是指您所在的班级。 $这不是来自CodeIgniter,而是来自PHP$这是指当前对象

模型通常用于处理所有数据库关系,因此基本上

$this->load->model("User_model");
表示“加载模型”模型名称,以便我们可以使用它

无论何时创建类

$something = new SomeClass();
然后,
$this
引用从某个类创建的实例,在本例中为$something。只要您在该类中,就可以使用$this引用该实例。因此:

class SomeClass {

 public $stuff = 'Some stuff';

 public function doStuff()
  {
    $this->stuff;
  }

}

这意味着您正在加载模型(User\u model和Auth\u model),以便可以使用这些模型中的函数。 例如:如果您有如下的Auth_模型

<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Auth_model extends CI_Model {
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    function insert_valid_val($valid_data)
    {
     //Write queries here and return some values.
    }

$此
引用全局CodeIgniter对象。如果
变量转储($this)
在构造函数或调用的方法中,您将看到所有被调用和初始化的代码。您可以通过加载一些库、助手、方法、语言、包或配置或框架类的
Loader.php
允许的任何其他方式跟踪更改。您将获得与输出
get_instance()类似的输出
功能

该结构使用Config.php核心系统文件的
load()
方法,您可以在第119行的start处进行检查。第119行中的Model表示需要加载的文件类型。 基本上,它是指作用于所需的装入器类方法(model、helper等)的配置类的装入方法

<?php 
class User extends CI_Controller {

    function __construct() 
    {
        parent::__construct(); 
        $this->template->set_layout('adminLayout.php');
        $this->load->model("User_model");
        $this->load->Model('Auth_model'); 
    }


    function index()
    {
        $this->Auth_model->isLoggedIn();
        $this->template->title('Admin ::');
        $this->template->build('admin/index');
        $returned_val = $this->Auth_model->insert_valid_val("send some array");
print_r($retunred_val);
    }
?>