Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 类拉威尔模型_Php_Laravel - Fatal编程技术网

Php 类拉威尔模型

Php 类拉威尔模型,php,laravel,Php,Laravel,我想做一个像模特一样能说会道的人。Eloquence类的函数都是静态的,但它们使用非静态$table作为变量来指示模型的类。如何在静态函数中使用非静态变量 编辑1:如果我理解得很好,函数实际上是非静态的,但另一个函数正在创建该非静态函数的新静态实例。那么现在我想知道如何在不使用laravel的情况下实现这一点?你说的雄辩类的函数都是静态的,但事实并非如此。相反,它使用静态风格的方法调用,这是因为Laravel的Facade类 摘自Laravel的文档: class Model { pub

我想做一个像模特一样能说会道的人。Eloquence类的函数都是静态的,但它们使用非静态$table作为变量来指示模型的类。如何在静态函数中使用非静态变量


编辑1:如果我理解得很好,函数实际上是非静态的,但另一个函数正在创建该非静态函数的新静态实例。那么现在我想知道如何在不使用laravel的情况下实现这一点?

你说的
雄辩类的函数都是静态的
,但事实并非如此。相反,它使用静态风格的方法调用,这是因为Laravel的
Facade

摘自Laravel的文档:

class Model {
    public static function __callStatic($method, $arguments) 
    {
        // create an instance of this model
        $instance = new static; 

        // dynamically call instance method, with the same arguments
        return call_user_func_array(array($instance, $method), $arguments);
    }
}
Facades为中可用的类提供“静态”接口 应用程序的IoC容器。Laravel船舶有许多正面,以及 你可能在不知不觉中使用过它们!拉维尔 “立面”是国际奥委会底层阶级的“静态代理” 容器,在 保持比传统静态测试更高的可测试性和灵活性 方法


你问
如何在静态函数中使用非静态变量?
希望你得到答案。要获得更清晰的概念,请阅读Laravel的网站。

在幕后,雄辩的代理类方法到实例方法

示例:

class Model {
    public static function __callStatic($method, $arguments) 
    {
        // create an instance of this model
        $instance = new static; 

        // dynamically call instance method, with the same arguments
        return call_user_func_array(array($instance, $method), $arguments);
    }
}

请看一下实际实施情况。

此答案将涵盖您想要了解的内容: