當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Convert::save方法代碼示例

本文整理匯總了PHP中Convert::save方法的典型用法代碼示例。如果您正苦於以下問題:PHP Convert::save方法的具體用法?PHP Convert::save怎麽用?PHP Convert::save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Convert的用法示例。


在下文中一共展示了Convert::save方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: actionCreate


//.........這裏部分代碼省略.........
                     $keys = array_keys($list);
                     $keys_ok = true;
                     for ($i = 0; $i < count($keys); ++$i) {
                         if (!is_numeric($keys[$i])) {
                             $keys_ok = false;
                         }
                     }
                     if ($keys_ok) {
                         $model->data_to_use = base64_encode(serialize($list));
                     } else {
                         $this->_sendResponse(500, sprintf('Parameter <b>%s</b> is invalid json format for model <b>%s</b>. JSON structure should be: [{"###KEY_TO_REPLACE###":"Replaced Value 1","###KEY###":"Key 1"},{"###KEY_TO_REPLACE###":"Replaced Value 2","###KEY###":"Key 2"}]', 'data', $_GET['model']));
                     }
                 } else {
                     $model->data_to_use = base64_encode(serialize(array()));
                 }
                 break;
             case 'csv':
                 $delimiter = ';';
                 $enclosure = '"';
                 if ($model->data_parameters != null && $model->data_parameters != '') {
                     $params = explode('||', $model->data_parameters);
                     foreach ($params as $param) {
                         $param = explode('==', $param);
                         $key = $param[0];
                         $value = isset($param[1]) ? $param[1] : '';
                         switch ($key) {
                             case 'delimiter':
                                 $delimiter = $value;
                                 break;
                             case 'enclosure':
                                 $enclosure = $value;
                                 break;
                             default:
                                 $this->_sendResponse(500, sprintf('Parameter <b>%s</b> is invalid format for model <b>%s</b>. Valid value for CSV is: \'setting1==value||setting2==value\', example: \'delimiter==;||enclosure=="\', default delimiter is: \';\', default enclosure is: \'"\'', 'data_parameters', $_GET['model']));
                                 break;
                         }
                     }
                 }
                 $data = CSV::toArray($model->data, $delimiter, $enclosure);
                 if (count($data) > 0) {
                     if (count($data) > 1) {
                         $header = $data[0];
                         $list = array();
                         for ($i = 1; $i < count($data); ++$i) {
                             $row = array();
                             for ($c = 0; $c < count($header); ++$c) {
                                 $row[$header[$c]] = isset($data[$c]) ? $data[$c] : '';
                             }
                             $list[] = $row;
                         }
                         $model->data_to_use = base64_encode(serialize($list));
                     } else {
                         $this->_sendResponse(500, sprintf('Parameter <b>%s</b> is empty for model <b>%s</b>. CSV should contain more lines. Not only one header line.', 'data', $_GET['model']));
                     }
                 } else {
                     $model->data_to_use = base64_encode(serialize(array()));
                 }
                 break;
             default:
                 $this->_sendResponse(500, sprintf('Parameter <b>%s</b> is invalid for model <b>%s</b>, allowed values: [json, csv]', 'data_type', $_GET['model']));
                 break;
         }
     }
     // Try to save the model
     if ($model->save()) {
         // Saving was OK
         if ($currentModel == 'convert') {
             if ($model->background == 1) {
                 // we send work to background, user can pool status of convert
                 $jobSetId = Svg2Pdf::BatchConvert(base64_decode($model->svg), unserialize(base64_decode($model->data_to_use)), $model->background);
                 $model->backgroud_job_set_id = $jobSetId;
                 $model->save();
             } else {
                 // we send work to do it now, user wait for result in open connection
                 $pdf = base64_encode(Svg2Pdf::BatchConvert(base64_decode($model->svg), unserialize(base64_decode($model->data_to_use))));
                 $model->result = $pdf;
                 $model->save();
             }
             // do not return all data
             $return_array = array('id' => $model->id, 'background' => $model->background, 'result' => $model->result);
         }
         $this->_sendResponse(200, $this->_getObjectEncoded($_GET['model'], $return_custom ? $return_array : $model->attributes));
     } else {
         // Errors occurred
         $msg = "<h1>Error</h1>";
         $msg .= sprintf("Couldn't create model <b>%s</b>", $_GET['model']);
         $msg .= "<ul>";
         foreach ($model->errors as $attribute => $attr_errors) {
             $msg .= "<li>Attribute: {$attribute}</li>";
             $msg .= "<ul>";
             foreach ($attr_errors as $attr_error) {
                 $msg .= "<li>{$attr_error}</li>";
             }
             $msg .= "</ul>";
         }
         $msg .= "</ul>";
         $this->_sendResponse(500, $msg);
     }
     var_dump($_REQUEST);
 }
開發者ID:lidijakralj,項目名稱:bober,代碼行數:101,代碼來源:ApiController.php


注:本文中的Convert::save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。