本文整理汇总了PHP中JsonHelper::sendJsonHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP JsonHelper::sendJsonHeaders方法的具体用法?PHP JsonHelper::sendJsonHeaders怎么用?PHP JsonHelper::sendJsonHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonHelper
的用法示例。
在下文中一共展示了JsonHelper::sendJsonHeaders方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionExport
public function actionExport()
{
$this->requirePostRequest();
$result = new ArtVandelay_ExportedDataModel(array('assets' => $this->_exportAssets(), 'categories' => $this->_exportCategories(), 'fields' => $this->_exportFields(), 'globals' => $this->_exportGlobals(), 'sections' => $this->_exportSections(), 'tags' => $this->_exportTags()));
$json = $result->toJson();
if (craft()->request->getParam('download')) {
HeaderHelper::setDownload('export.json', strlen($json));
}
JsonHelper::sendJsonHeaders();
echo $json;
craft()->end();
}
示例2: actionRerunTask
/**
* Re-runs a failed task.
*
* @return null
*/
public function actionRerunTask()
{
$this->requireAjaxRequest();
$this->requirePostRequest();
craft()->userSession->requirePermission('accessCp');
$taskId = craft()->request->getRequiredPost('taskId');
$task = craft()->tasks->rerunTaskById($taskId);
if (!craft()->tasks->isTaskRunning()) {
JsonHelper::sendJsonHeaders();
craft()->request->close(JsonHelper::encode($task->getInfo()));
craft()->tasks->runPendingTasks();
} else {
$this->returnJson($task->getInfo());
}
craft()->end();
}
示例3: returnAjaxError
/**
* Formats a PHP error into JSON before returning it to the client.
*
* @param integer $code error code
* @param string $message error message
* @param string $file error file
* @param string $line error line
*/
public function returnAjaxError($code, $message, $file, $line)
{
if ($this->config->get('devMode')) {
$outputTrace = '';
$trace = debug_backtrace();
// skip the first 3 stacks as they do not tell the error position
if (count($trace) > 3) {
$trace = array_slice($trace, 3);
}
foreach ($trace as $i => $t) {
if (!isset($t['file'])) {
$t['file'] = 'unknown';
}
if (!isset($t['line'])) {
$t['line'] = 0;
}
if (!isset($t['function'])) {
$t['function'] = 'unknown';
}
$outputTrace .= "#{$i} {$t['file']}({$t['line']}): ";
if (isset($t['object']) && is_object($t['object'])) {
$outputTrace .= get_class($t['object']) . '->';
}
$outputTrace .= "{$t['function']}()\n";
}
$errorArr = array('error' => $code . ' : ' . $message, 'trace' => $outputTrace, 'file' => $file, 'line' => $line);
} else {
$errorArr = array('error' => $message);
}
JsonHelper::sendJsonHeaders();
echo JsonHelper::encode($errorArr);
$this->end();
}
示例4: returnJson
/**
* Outputs JSON encoded data to standard output stream, useful during AJAX requests
*
* @param array $variables
*/
public function returnJson($variables = array())
{
JsonHelper::sendJsonHeaders();
// Output it into a buffer, in case TasksService wants to close the connection prematurely
ob_start();
echo JsonHelper::encode($variables);
craft()->end();
}
示例5: actionExport
public function actionExport()
{
$this->requirePostRequest();
$fields = craft()->request->getParam('selectedFields');
$fieldsObj = craft()->fieldManager_export->export($fields);
// Support PHP <5.4, JSON_PRETTY_PRINT = 128, JSON_NUMERIC_CHECK = 32
$json = json_encode($fieldsObj, 128 | 32);
HeaderHelper::setDownload('export.json', strlen($json));
JsonHelper::sendJsonHeaders();
echo $json;
craft()->end();
}
示例6: returnJson
/**
* Respond with JSON
*
* @param array $var The array to JSON-encode and return
*/
public function returnJson($var)
{
JsonHelper::sendJsonHeaders();
echo JsonHelper::encode($var);
craft()->end();
}