Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.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 找不到yii模型属性_Php_Oop_Yii - Fatal编程技术网

Php 找不到yii模型属性

Php 找不到yii模型属性,php,oop,yii,Php,Oop,Yii,我是yii的新手。在SiteController中的默认actionLogin()方法中,我正在搜索 $model->attribtes是否已定义 $model->attributes=$\u POST['LoginForm'] 我在LoginForm、CFormModel、CModel类中搜索,但找不到。这是一种setter方法吗? 创建模型实例后,我们通常需要使用最终用户提交的数据填充其属性。这可以通过以下大规模任务方便地完成: $model=new LoginForm; if(isset(

我是yii的新手。在SiteController中的默认actionLogin()方法中,我正在搜索
$model->attribtes
是否已定义

$model->attributes=$\u POST['LoginForm']

我在LoginForm、CFormModel、CModel类中搜索,但找不到。这是一种setter方法吗?

创建模型实例后,我们通常需要使用最终用户提交的数据填充其属性。这可以通过以下大规模任务方便地完成:

$model=new LoginForm;
if(isset($_POST['LoginForm']))
    $model->attributes=$_POST['LoginForm'];
最后一个语句被称为massive assignment,它在 $\将['LoginForm']发布到相应的模型属性。它相当于以下作业:

foreach($_POST['LoginForm'] as $name=>$value)
    {
        if($name is a safe attribute)
            $model->$name=$value;
    }
Yii通过一个实例提供对许多其他事物的访问 变量,例如数据库字段、关系、事件处理程序和 喜欢这些“属性”是Yii中非常强大的一部分 框架,虽然可以在不理解的情况下使用它们, 一个人如果不躲在被子底下,就不能真正使用全部的能量 一点

属性
是CActiveRecord的一个属性,是的,它有getter和setter方法

然后是你想看的地方

创建模型实例后,我们通常需要使用最终用户提交的数据填充其属性。这可以通过以下大规模任务方便地完成:

$model=new LoginForm;
if(isset($_POST['LoginForm']))
    $model->attributes=$_POST['LoginForm'];
最后一个语句被称为massive assignment,它在 $\将['LoginForm']发布到相应的模型属性。它相当于以下作业:

foreach($_POST['LoginForm'] as $name=>$value)
    {
        if($name is a safe attribute)
            $model->$name=$value;
    }
Yii通过一个实例提供对许多其他事物的访问 变量,例如数据库字段、关系、事件处理程序和 喜欢这些“属性”是Yii中非常强大的一部分 框架,虽然可以在不理解的情况下使用它们, 一个人如果不躲在被子底下,就不能真正使用全部的能量 一点

属性
是CActiveRecord的一个属性,是的,它有getter和setter方法

然后是你想看的地方


我打印了班级家长($model)的输出。它说这是从CComponent继承的。所以我认为$attributes属性是在CComponent类中的u set()方法中声明的。

我打印了类u parents($model)的输出。它说这是从CComponent继承的。所以我认为$attributes属性是在CComponent类的uu set()方法中声明的。

属性实际上是模型中的一个getter/setter方法。将数组传递给它将尝试对这些属性进行“mass”设置。$\u POST['LoginForm']中的所有元素都需要在模型中具有相应的属性。在Yii附带的LoginForm模型中,这些被设置为属性(即,
public$username;
),
attributes
属性将
$username
分配给数组中的相关值(
'username'=>'myusername'
)。

属性实际上是模型中的一种getter/setter方法。将数组传递给它将尝试对这些属性进行“mass”设置。$\u POST['LoginForm']中的所有元素都需要在模型中具有相应的属性。在Yii附带的LoginForm模型中,这些被设置为属性(即
public$username;
),
属性将
$username
与数组中的相关值一起分配(
'username'=>'myusername'
)。

谢谢您的回答。这对我来说很清楚。但我还是很困惑。在CavActiveRecord类中,有一个名为$\u attributes而不是$attributes的属性。然后我打印了class_parents($model)的输出。它说这是从CComponent继承的。所以我认为$attributes propery是在CComponent类的uu set()方法中声明的。但我不确定这一点。@Namal查看的u get方法的前几行。它允许您执行$model->attributes并自动尝试调用$model->getAttributes()。谢谢你的确认。谢谢你的回答。这对我来说很清楚。但我还是很困惑。在CavActiveRecord类中,有一个名为$\u attributes而不是$attributes的属性。然后我打印了class_parents($model)的输出。它说这是从CComponent继承的。所以我认为$attributes propery是在CComponent类的uu set()方法中声明的。但我不确定这一点。@Namal查看的u get方法的前几行。它允许您执行$model->attributes并自动尝试调用$model->getAttributes()。谢谢你的确认。