Yii Framework Forum: Multiple Rules in CFormModel for 'on' - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Multiple Rules in CFormModel for 'on'

#1 User is offline   Mayur Ahir 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 08-July 11

Posted 08 July 2011 - 03:25 AM

This is my function in Model
public function rules() {
        return array(
            array('fDate, tDate', 'checkDate', 'on' => 'addandterm'),
            array('fDate, tDate', 'checkDate', 'on' => 'benifits'),
            array('empType', 'required', 'on' => 'addrloc'),
            array('empType', 'required', 'on' => 'ageprof'),
            array('empType', 'required', 'on' => 'benifits'),
            array('businessUnit', 'required'),
            array('department', 'buNotAll'),
            array('designation', 'deptNotAll'),
            array('location', 'desgNotAll'),
        );
    }


My Problem is is there any workaround to reduce code repetition i.e.
array('empType', 'required', 'on' => 'addrloc'),
array('empType', 'required', 'on' => 'ageprof'),
array('empType', 'required', 'on' => 'benifits'),


to something like

array('empType', 'required', 'on' => array('addrloc','ageprof','benifits'......),

0

#2 User is offline   Soumya 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 21-November 10
  • Location:Kolkata, India

Posted 07 August 2011 - 03:43 AM

View PostMayur Ahir, on 08 July 2011 - 03:25 AM, said:

This is my function in Model
public function rules() {
        return array(
            array('fDate, tDate', 'checkDate', 'on' => 'addandterm'),
            array('fDate, tDate', 'checkDate', 'on' => 'benifits'),
            array('empType', 'required', 'on' => 'addrloc'),
            array('empType', 'required', 'on' => 'ageprof'),
            array('empType', 'required', 'on' => 'benifits'),
            array('businessUnit', 'required'),
            array('department', 'buNotAll'),
            array('designation', 'deptNotAll'),
            array('location', 'desgNotAll'),
        );
    }


My Problem is is there any workaround to reduce code repetition i.e.
array('empType', 'required', 'on' => 'addrloc'),
array('empType', 'required', 'on' => 'ageprof'),
array('empType', 'required', 'on' => 'benifits'),


to something like

array('empType', 'required', 'on' => array('addrloc','ageprof','benifits'......),



You can write as follows:
array('empType', 'required', 'on' => 'addrloc ,ageprof ,benifits')

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users