Reputation: 3103
I am new to yii.. I am developing a form in which i am having a registration form in which i need to get education details of a student. It includes
'Post Graduation',
'Graduation' and
'Schooling'
details. Each of this will be having pass year, qualification etc fields.
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',
);
}
How can i use the same model to create similar elements to get these details separately for
'Post Graduation',
'Graduation' and
'Schooling'
I tried by creating different objects for the model and including them in the form.
$postGraduate = new CandidateQualification;
$graduate = new CandidateQualification;
$preGraduate = new CandidateQualification;
But this create problem as all of them will be having same name and validation also wont help. Please provide any solution.
Thanks in advance.
Upvotes: 1
Views: 106
Reputation: 7419
For this Specific task you need to use scenarios as others have mentioned.Understanding Scenarios. Once you have these defined in your model
all you need is to create instance of classes with required scenario
for example you can do
$studentModel = new student('pregrad');
$studentModel = new student('grad');
$studentModel = new student('postgrad');
and when ever form is rendeded using same $studentModel
validations would be different
Upvotes: 1
Reputation: 371
Use scenario`s Luke.
Scenarios are an extremely useful tool for separating validation tasks on any class you use derived from CModel. In this tutorial we will use CActiveRecord.
Upvotes: 1