本文整理汇总了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);
}