Yii Framework Forum: Validate file only on create not update? - Yii Framework Forum

Jump to content

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

Validate file only on create not update? Rate Topic: -----

#1 User is offline   mech7 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 220
  • Joined: 26-March 09

Posted 16 March 2010 - 09:21 AM

What is the best way to set a file for validate only on create.. now I have in my model:

public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('title, pdf', 'required'),
            array('title', 'length', 'max'=>125),
            array('description', 'safe'),
            array('pdf', 'file',
                'types'=> 'pdf',
                'maxSize' => 1024 * 1024 * 10, // 10MB
                'tooLarge' => 'The file was larger than 10MB. Please upload a smaller file.',
            ),
        );
    }


But this will require to upload a new file at update..
0

#2 User is offline   Matt Kelliher 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 12-February 10
  • Location:Tampa, FL

Posted 16 March 2010 - 09:28 AM

You can use scenarios in your validation rules, such as
array('pdf', 'file',
    'types'=> 'pdf',
    'maxSize' => 1024 * 1024 * 10, // 10MB
    'tooLarge' => 'The file was larger than 10MB. Please upload a smaller file.',
    'on' => 'insert',
),

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