当前位置: 首页>>代码示例>>PHP>>正文


PHP Note::validate方法代码示例

本文整理汇总了PHP中Note::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Note::validate方法的具体用法?PHP Note::validate怎么用?PHP Note::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Note的用法示例。


在下文中一共展示了Note::validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testUploadInvalid

 /**
  * Tests the note upload action with invalid input.
  */
 public function testUploadInvalid()
 {
     $this->init();
     // Empty title
     $fakeNote = new Note();
     $fakeNote->setAttributes($this->noteAttributes);
     $fakeNote->title = null;
     $this->assertFalse($fakeNote->validate());
     // Lengthy title
     $fakeNote = new Note();
     $fakeNote->setAttributes($this->noteAttributes);
     Yii::import('ext.randomness.*');
     $fakeNote->title = Randomness::randomString(Note::MAX_TITLE_LENGTH + 1);
     $this->assertFalse($fakeNote->validate());
     // Empty description
     $fakeNote = new Note();
     $fakeNote->setAttributes($this->noteAttributes);
     $fakeNote->description = null;
     $this->assertFalse($fakeNote->validate());
     // Invalid course_id
     $fakeNote = new Note();
     $fakeNote->setAttributes($this->noteAttributes);
     $fakeNote->course_id = self::INVALID_ID;
     $this->assertFalse($fakeNote->validate());
     // Empty faculty_id
     $fakeNote = new Note();
     $fakeNote->setAttributes($this->noteAttributes);
     $fakeNote->faculty_id = null;
     $this->assertFalse($fakeNote->validate());
     // Invalid faculty_id
     $fakeNote->faculty_id = self::INVALID_ID;
     $this->assertFalse($fakeNote->validate());
     // Invalid file type
     $fakeNote = new Note();
     $fakeNote->setAttributes($this->noteAttributes);
     $fakeFile = $this->testFile;
     $fakeFile['name'] = 'Fake.avi';
     $fakeFile['type'] = 'video/x-msvideo';
     $fakeNote->file = new CUploadedFile($fakeFile['name'], $fakeFile['tmp_name'], $fakeFile['type'], $fakeFile['size'], $fakeFile['error']);
     $this->assertFalse($fakeNote->validate());
     // Invalid file size
     $fakeNote = new Note();
     $fakeNote->setAttributes($this->noteAttributes);
     $fakeFile = $this->testFile;
     $fakeFile['size'] = Note::MAX_FILE_SIZE * 2;
     $fakeNote->file = new CUploadedFile($fakeFile['name'], $fakeFile['tmp_name'], $fakeFile['type'], $fakeFile['size'], $fakeFile['error']);
     $this->assertFalse($fakeNote->validate());
     // Empty file and raw text
     $fakeNote = new Note();
     $fakeNote->setAttributes($this->noteAttributes);
     $fakeNote->raw_file_text = null;
     $fakeNote->file = null;
     $this->assertFalse($fakeNote->validate());
 }
开发者ID:ekospinach,项目名称:berkuliah,代码行数:57,代码来源:NoteTest.php

示例2: actionUpload

 /**
  * Uploads a note.
  */
 public function actionUpload()
 {
     $model = new Note();
     if (isset($_POST['Note'])) {
         $model->attributes = $_POST['Note'];
         if ($model->validate()) {
             // sets extension
             $extension = 'htm';
             if (empty($model->raw_file_text)) {
                 $noteFile = CUploadedFile::getInstance($model, 'file');
                 $extension = $noteFile->extensionName;
             }
             $model->type = Note::getTypeFromExtension($extension);
             $model->save(false);
             // saves file
             $filePath = Yii::app()->params['notesDir'];
             if (empty($model->raw_file_text)) {
                 $noteFile = CUploadedFile::getInstance($model, 'file');
                 $noteFile->saveAs($filePath . $model->id . '.' . $noteFile->extensionName);
             } else {
                 touch($filePath . $model->id . '.htm');
                 file_put_contents($filePath . $model->id . '.htm', $model->raw_file_text);
             }
             $event = new UploadEvent($this);
             $event->student = $model->student;
             $this->onNewUpload($event);
             $message['text'] = 'Berkas berhasil diunggah.';
             $message['type'] = 'general';
             $message['default_text'] = 'Saya baru saja mengunggah ' . $model->title . ' pada BerKuliah!';
             $message['name'] = $model->title;
             $message['link'] = array('note/view', 'id' => $model->id);
             $message['picture'] = $model->getTypeIcon();
             $message['caption'] = $model->course->name;
             $message['description'] = $model->description;
             Yii::app()->user->addShareMessage($message);
             $this->redirect(array('home/index'));
         } else {
             $model->faculty_id = null;
             Yii::app()->user->setNotification('danger', 'Terdapat kesalahan pengisian.');
         }
     }
     $this->render('upload', array('model' => $model));
 }
开发者ID:ekospinach,项目名称:berkuliah,代码行数:46,代码来源:NoteController.php


注:本文中的Note::validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。