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


PHP Song::validate方法代码示例

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


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

示例1: actionUpmusic

 public function actionUpmusic()
 {
     $songModel = new Song();
     if (isset($_POST['Song'])) {
         $songModel->attributes = $_POST['Song'];
         $songModel->userid = Yii::app()->session['uid'];
         if ($songModel->validate()) {
             if (!empty($_FILES['songname']['tmp_name'])) {
                 $file = $_FILES['songname'];
                 if (!MusicTypeCheck($file['name'], $file['size'])) {
                     Yii::app()->user->setFlash('upstatus', 'Sorry, 音乐文件大小或格式错误 :(');
                     $this->redirect(array("Upmusic"));
                     die;
                 }
                 $type = "." . GetFileExtension($file['name']);
                 Yii::import('application.vendors.*');
                 require_once 'Qiniu/rs.php';
                 require_once 'Qiniu/io.php';
                 $bucket = Yii::app()->params['bucket'];
                 $accessKey = Yii::app()->params['accessKey'];
                 $secretKey = Yii::app()->params['secretKey'];
                 $newname = time() . rand(10000, 99999) . $type;
                 //先保存记录
                 $songModel->song = $newname;
                 if ($songModel->save()) {
                     /**
                      * 
                      */
                 } else {
                     Yii::app()->user->setFlash('upstatus', 'Sorry,系统错误,上传音乐失败 :(');
                 }
                 Qiniu_SetKeys($accessKey, $secretKey);
                 $putPolicy = new Qiniu_RS_PutPolicy($bucket);
                 $upToken = $putPolicy->Token(null);
                 list($ret, $err) = Qiniu_Put($upToken, $newname, file_get_contents($file['tmp_name']), null);
                 if ($err === null) {
                     //成功
                     /***
                      * 
                      */
                     $this->redirect(array('admin/Imusic'));
                 } else {
                     //失败
                     Yii::app()->user->setFlash('upstatus', 'Sorry,系统错误,上传音乐失败 :(');
                 }
             }
         }
     }
     $data = array('songModel' => $songModel);
     $this->render("upmusic", $data);
 }
开发者ID:returncn,项目名称:chen-xia-cms,代码行数:51,代码来源:AdminController.php

示例2: actionUpdate

 public function actionUpdate($id)
 {
     /* @var Artist $model */
     $model = $this->loadModel($id);
     // check access
     if (!Yii::app()->user->checkAccess('edit artist')) {
         throw new CHttpException(401);
     }
     // does this artists exists in our DB?
     if ($model === null) {
         Yii::log("Artist update requested with id {$id} but no such artist found!", CLogger::LEVEL_INFO, __METHOD__);
         throw new CHttpException(404, Yii::t("MusicModule.general", 'The requested page does not exist.'));
     }
     // enable adding songs by default (will be changed below if needed to)
     $enable_add_more_songs = true;
     if (isset($_POST['Artist'])) {
         // start optimistically
         $all_songs_valid = true;
         $songs_to_save = array();
         $success_saving_all = true;
         $model->attributes = $_POST['Artist'];
         if (isset($_POST['Song'])) {
             if (count($_POST['Song']) > Song::MAX_SONGS_PER_ARTIST) {
                 /*
                  * server side protection against attempt to submit more than MAX_SONGS_PER_ARTIST
                  * this should be accompanied with a client side (JS) protection.
                  * If its accompanied with client side protection then going into this code block means our system
                  * is being abused/"tested". No need to give a polite error message.
                  */
                 throw new CHttpException(500, Yii::t("MusicModule.forms", "The max amount of allowed songs is {max_songs_num}", array('{max_songs_num}' => Song::MAX_SONGS_PER_ARTIST)));
             }
             foreach ($_POST['Song'] as $index => $submitted_song) {
                 // We could have empty songs which means empty submitted forms in POST. Ignore those:
                 if ($submitted_song['title'] == '') {
                     // empty one - skip it, if you please.
                     continue;
                 }
                 // next, validate each submitted song instance
                 if ((int) $submitted_song['id'] > 0) {
                     /* Validate that the submitted song belong to this artist */
                     $song = Song::model()->findByPk($submitted_song['id']);
                     if ($song->artist->id != $model->id) {
                         Yii::log("Attempts to update Song with an id of {$song->id} but it belongs to an Artist with an id of {$song->model->id}" . " and not 'this' artist with id = {$model->id}", CLogger::LEVEL_ERROR, __METHOD__);
                         throw new CHttpException(500, "Error occurred");
                     }
                 } else {
                     // this submitted song object is a new model. instantiate one:
                     $song = new Song();
                 }
                 $song->attributes = $submitted_song;
                 if (!$song->validate()) {
                     // at least one invalid song:
                     $all_songs_valid = false;
                     // we do not 'break' here since we want validation on all song at the same shot
                 } else {
                     // put aside the valid song to be saved
                     $songs_to_save[] = $song;
                 }
             }
             // while we know that songs were submitted, determine if to show 'adding songs' or no.
             // a check whether the max songs per artist was exceeded was performed already above.
             if (count($_POST['Song']) == Song::MAX_SONGS_PER_ARTIST) {
                 $enable_add_more_songs = false;
             }
         }
         if ($all_songs_valid && $model->validate()) {
             /* all songs (if any) were valid and artist object is valid too. Save it all in one transaction. Save first the
              * artist as we need its id for its songs records
              */
             $trans = Yii::app()->db->beginTransaction();
             try {
                 // use aux variable for manipulating the image file.
                 $image = CUploadedFile::getInstance($model, 'icon_filename');
                 // check if a new image was submitted or not:
                 if ($image) {
                     /* the only thing that might have changed in the update is the extension name of the image (if you support more than 'only jpeg').
                      * therefore, if something was submitted, and since we already know the ID of the artist (this is an update scenario), we can
                      * determine the full updated icon_filename attribute of the model prior to its save() (unlike in create action - see there...).
                      */
                     $model->icon_filename = $model->getImageFsFilename($image);
                 }
                 $model->save(false);
                 // save the updated image, if any
                 if ($image) {
                     $image->saveAs($model->getImageFsFilename($image));
                 }
                 // save songs
                 foreach ($songs_to_save as $song) {
                     $song->save(false);
                 }
                 $trans->commit();
             } catch (Exception $e) {
                 // oops, saving artist or its songs failed. rollback, report us, and show the user an error.
                 $trans->rollback();
                 Yii::log("Error occurred while saving (update scenario) artist or its 'songs'. Rolling back... . Failure reason as reported in exception: " . $e->getMessage(), CLogger::LEVEL_ERROR, __METHOD__);
                 Yii::app()->user->setFlash('error', Yii::t("MusicModule.forms", "Error occurred"));
                 $success_saving_all = false;
             }
             if ($success_saving_all) {
                 $success_msg = count($songs_to_save) > 0 ? "Artist and song records have been updated" : "Artist record have been updated";
//.........这里部分代码省略.........
开发者ID:alejandrososa,项目名称:ventasYii,代码行数:101,代码来源:asd.php


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