Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.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_Yii - Fatal编程技术网

Php 如何在yii中使用相同模型的相同元素?

Php 如何在yii中使用相同模型的相同元素?,php,yii,Php,Yii,我是yii的新手。。我正在开发一个表格,在其中我有一个注册表格,在其中我需要获得一个学生的教育细节。它包括 'Post Graduation', 'Graduation' and 'Schooling' 细节。其中每一项都将有及格年份、资格等领域 public function attributeLabels() { return array( '

我是yii的新手。。我正在开发一个表格,在其中我有一个注册表格,在其中我需要获得一个学生的教育细节。它包括

                'Post Graduation',
                'Graduation' and 
                'Schooling' 
细节。其中每一项都将有及格年份、资格等领域

public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'user_id' => 'User',
            'qualification_id' => 'Qualification',
            'specialization_id' => 'Specialization',
            'pass_year' => 'Pass Year',
            'university_id' => 'University',
            'duration_from' => 'Duration From',
            'duration_to' => 'Duration To',
            'percentage_marks' => '% of Marks / GPA',
            'course_type_id' => 'Course Type',
            'awards' => 'Awards & Scholarships',
        );
    }
如何使用同一个模型创建类似的元素,以分别获取这些详细信息

                'Post Graduation',
                'Graduation' and 
                'Schooling' 
我尝试为模型创建不同的对象,并将它们包含在表单中

    $postGraduate = new CandidateQualification;
    $graduate = new CandidateQualification;
    $preGraduate = new CandidateQualification;
但这会产生问题,因为它们都有相同的名称,验证也不会有帮助。请提供任何解决方案

提前感谢。

使用Luke

场景是一个非常有用的工具,用于在从CModel派生的任何类上分离验证任务。在本教程中,我们将使用CActiveRecord


对于此特定任务,您需要使用其他人提到的场景。。一旦您在
模型中定义了这些,您所需要的就是创建具有所需场景的类的实例

比如你能做什么

$studentModel = new student('pregrad');
$studentModel = new student('grad');
$studentModel = new student('postgrad');
当表单使用相同的
$studentModel
进行渲染时,验证将不同

yii场景?