本文整理汇总了PHP中SpoonHTTP::setHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP SpoonHTTP::setHeaders方法的具体用法?PHP SpoonHTTP::setHeaders怎么用?PHP SpoonHTTP::setHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpoonHTTP
的用法示例。
在下文中一共展示了SpoonHTTP::setHeaders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
// if the application wasn't defined before we will define it
if (!defined('NAMED_APPLICATION')) {
define('NAMED_APPLICATION', 'frontend');
}
// set the module
$this->setModule(SpoonFilter::getGetValue('module', null, ''));
// set the requested file
$this->setFile(SpoonFilter::getGetValue('file', null, ''));
// set the language
$this->setLanguage(SpoonFilter::getGetValue('language', FrontendLanguage::getActiveLanguages(), SITE_DEFAULT_LANGUAGE));
// create a new template instance (this will handle all stuff for us)
$tpl = new FrontendTemplate();
// enable addslashes on each locale
$tpl->setAddSlashes(true);
// set correct headers
SpoonHTTP::setHeaders('content-type: application/javascript');
// fetch the template path
if ($this->module == 'core') {
$file = FRONTEND_CORE_PATH . '/js/' . $this->getFile();
} else {
$file = FRONTEND_MODULES_PATH . '/' . $this->getModule() . '/js/' . $this->getFile();
}
// output the template
$tpl->display(FrontendTheme::getPath($file), true);
}
示例2: outputCSV
/**
* Output a CSV-file as a download
*
* @param string $filename The name of the file.
* @param array $array The array to convert.
* @param array[optional] $columns The column names you want to use.
* @param array[optional] $excludeColumns The columns you want to exclude.
*/
public static function outputCSV($filename, array $array, array $columns = null, array $excludeColumns = null)
{
// get settings
$splitCharacter = BackendAuthentication::getUser()->getSetting('csv_split_character');
$lineEnding = BackendAuthentication::getUser()->getSetting('csv_line_ending');
// reformat
if ($lineEnding == '\\n') {
$lineEnding = "\n";
}
if ($lineEnding == '\\r\\n') {
$lineEnding = "\r\n";
}
// convert into CSV
$csv = SpoonFileCSV::arrayToString($array, $columns, $excludeColumns, $splitCharacter, '"', $lineEnding);
// set headers for download
$headers[] = 'Content-type: application/csv; charset=' . SPOON_CHARSET;
$headers[] = 'Content-Disposition: attachment; filename="' . $filename;
$headers[] = 'Content-Length: ' . strlen($csv);
$headers[] = 'Pragma: no-cache';
// overwrite the headers
SpoonHTTP::setHeaders($headers);
// ouput the CSV
echo $csv;
exit;
}
示例3: execute
/**
* Execute the action
*/
public function execute()
{
// call parent, this will probably add some general CSS/JS or other required files
parent::execute();
// init vars
$templates = array();
$theme = BackendModel::getModuleSetting('core', 'theme');
$files[] = BACKEND_PATH . '/core/layout/editor_templates/templates.js';
$themePath = FRONTEND_PATH . '/themes/' . $theme . '/core/layout/editor_templates/templates.js';
if (SpoonFile::exists($themePath)) {
$files[] = $themePath;
}
// loop all files
foreach ($files as $file) {
// process file
$templates = array_merge($templates, $this->processFile($file));
}
// set headers
SpoonHTTP::setHeaders('Content-type: text/javascript');
// output the templates
if (!empty($templates)) {
echo 'CKEDITOR.addTemplates(\'default\', { imagesPath: \'/\', templates:' . "\n";
echo json_encode($templates) . "\n";
echo '});';
}
exit;
}
示例4: __construct
public function __construct()
{
// define the Named Application
if (!defined('NAMED_APPLICATION')) {
define('NAMED_APPLICATION', 'backend');
}
// set the module
$this->setModule(SpoonFilter::getGetValue('module', null, ''));
// set the requested file
$this->setFile(SpoonFilter::getGetValue('file', null, ''));
// set the language
$this->setLanguage(SpoonFilter::getGetValue('language', array_keys(BackendLanguage::getWorkingLanguages()), SITE_DEFAULT_LANGUAGE));
// build the path
if ($this->module == 'core') {
$path = BACKEND_CORE_PATH . '/js/' . $this->getFile();
} else {
$path = BACKEND_MODULES_PATH . '/' . $this->getModule() . '/js/' . $this->getFile();
}
// set correct headers
SpoonHTTP::setHeaders('content-type: application/javascript');
// create a new template instance (this will handle all stuff for us)
$tpl = new BackendTemplate();
// enable addslashes on each locale
$tpl->setAddSlashes(true);
// display
$tpl->display($path, true);
}
示例5: parse
/**
* Parse the ical and output into the browser.
*
* @param bool[optional] $headers Should the headers be set? (Use false if you're debugging).
*/
public function parse($headers = true)
{
// set headers
if ((bool) $headers) {
SpoonHTTP::setHeaders('Content-Disposition: inline; filename=' . SpoonFilter::urlise($this->getTitle()) . '.ics');
}
// call the parent
parent::parse($headers);
}
示例6: parse
/**
* Parse the iCal and output into the browser.
*
* @param bool $headers Should the headers be set? (Use false if you're debugging).
*/
public function parse($headers = true)
{
// set headers
if ((bool) $headers) {
\SpoonHTTP::setHeaders('Content-Disposition: inline; filename=' . CommonUri::getUrl($this->getTitle()) . '.ics');
}
// call the parent
parent::parse($headers);
}
示例7: parse
/**
* Export the templates as XML.
*/
protected function parse()
{
$xml = Model::createTemplateXmlForExport($this->selectedTheme);
$filename = 'templates_' . BackendModel::getUTCDate('d-m-Y') . '.xml';
$headers = array('Content-type: text/xml', 'Content-disposition: attachment; filename="' . $filename . '"');
\SpoonHTTP::setHeaders($headers);
echo $xml;
exit;
}
示例8: display
/**
* Output the template into the browser
* Will also assign the interfacelabels and all user-defined constants.
*
* @param string $template The path for the template.
* @param bool[optional] $customHeaders Are there custom headers set?
*/
public function display($template, $customHeaders = false)
{
$this->parseConstants();
$this->parseAuthenticatedUser();
$this->parseDebug();
$this->parseLabels();
$this->parseLocale();
$this->parseVars();
// parse headers
if (!$customHeaders) {
SpoonHTTP::setHeaders('Content-type: text/html;charset=' . SPOON_CHARSET);
}
parent::display($template);
}
示例9: createXML
/**
* Create the XML based on the locale items.
*
* @return void
*/
private function createXML()
{
// create XML
$xmlOutput = BackendLocaleModel::createXMLForExport($this->locale);
// xml headers
$headers[] = 'Content-Disposition: attachment; filename="locale_' . BackendModel::getUTCDate('d-m-Y') . '.xml"';
$headers[] = 'Content-Type: application/octet-stream;charset=utf-8';
$headers[] = 'Content-Length: ' . strlen($xmlOutput);
// set headers
SpoonHTTP::setHeaders($headers);
// output XML
echo $xmlOutput;
// stop script
exit;
}
示例10: createXML
/**
* Create the XML based on the locale items.
*/
private function createXML()
{
$charset = BackendModel::getContainer()->getParameter('kernel.charset');
// create XML
$xmlOutput = BackendLocaleModel::createXMLForExport($this->locale);
// xml headers
$headers[] = 'Content-Disposition: attachment; filename="locale_' . BackendModel::getUTCDate('d-m-Y') . '.xml"';
$headers[] = 'Content-Type: application/octet-stream;charset=' . $charset;
$headers[] = 'Content-Length: ' . strlen($xmlOutput);
// set headers
\SpoonHTTP::setHeaders($headers);
// output XML
echo $xmlOutput;
exit;
}
示例11: createCsv
/**
* Create the CSV.
*
* @return void
*/
private function createCsv()
{
// create csv
$csv = SpoonFileCSV::arrayToString($this->rows, $this->columnHeaders);
// set headers for download
$headers[] = 'Content-type: application/csv; charset=utf-8';
$headers[] = 'Content-Disposition: attachment; filename="' . date('Ymd_His') . '.csv"';
$headers[] = 'Content-Length: ' . strlen($csv);
$headers[] = 'Pragma: no-cache';
// overwrite the headers
SpoonHTTP::setHeaders($headers);
// output
echo $csv;
// exit here
exit;
}
示例12: downloadCSV
/**
* Sets the headers so we may download the CSV file in question
*
* @param string $path The full path to the CSV file you wish to download.
* @return array
*/
private function downloadCSV($path)
{
// check if the file exists
if (!SpoonFile::exists($path)) {
throw new SpoonFileException('The file ' . $path . ' doesn\'t exist.');
}
// fetch the filename from the path string
$explodedFilename = explode('/', $path);
$filename = end($explodedFilename);
// set headers for download
$headers[] = 'Content-type: application/csv; charset=' . SPOON_CHARSET;
$headers[] = 'Content-Disposition: attachment; filename="' . $filename . '"';
$headers[] = 'Pragma: no-cache';
// overwrite the headers
SpoonHTTP::setHeaders($headers);
// get the file contents
$content = SpoonFile::getContent($path);
// output the file contents
echo $content;
exit;
}
示例13: display
/**
* Output the template into the browser
* Will also assign the interfacelabels and all user-defined constants.
*
* @return void
* @param string $template The path for the template.
* @param bool[optional] $customHeaders Are there custom headers set?
*/
public function display($template, $customHeaders = false)
{
// parse constants
$this->parseConstants();
// parse authenticated user
$this->parseAuthenticatedUser();
// check debug
$this->parseDebug();
// parse the label
$this->parseLabels();
// parse locale
$this->parseLocale();
// parse some vars
$this->parseVars();
// parse headers
if (!$customHeaders) {
SpoonHTTP::setHeaders('Content-type: text/html;charset=utf-8');
}
// call the parent
parent::display($template);
}
示例14: exceptionAJAXHandler
/**
* This method will be called by the Spoon Exception handler and is specific for exceptions thrown in AJAX-actions
*
* @param object $exception The exception that was thrown.
* @param string $output The output that should be mailed.
*/
public static function exceptionAJAXHandler($exception, $output)
{
\SpoonHTTP::setHeaders('content-type: application/json');
$response = array('code' => $exception->getCode() != 0 ? $exception->getCode() : 500, 'message' => $exception->getMessage());
echo json_encode($response);
exit;
}
示例15: outputXML
/**
* Output as XML
*
* @param int $statusCode The status code.
* @param array $data The data to return.
*/
private static function outputXML($statusCode, array $data = null)
{
// redefine
$statusCode = (int) $statusCode;
// init vars
$charset = BackendModel::getContainer()->getParameter('kernel.charset');
$pathChunks = explode(DIRECTORY_SEPARATOR, trim(dirname(__FILE__), DIRECTORY_SEPARATOR));
$version = $pathChunks[count($pathChunks) - 2];
$version = strtolower($version);
// init XML
$XML = new \DOMDocument('1.0', $charset);
// set some properties
$XML->preserveWhiteSpace = false;
$XML->formatOutput = true;
// create root element
$root = $XML->createElement('fork');
// add attributes
$root->setAttribute('status_code', $statusCode);
$root->setAttribute('status', $statusCode == 200 ? 'ok' : 'error');
$root->setAttribute('version', FORK_VERSION);
$root->setAttribute('endpoint', SITE_URL . '/api/' . $version);
// append
$XML->appendChild($root);
// build XML
array_walk($data, array(__CLASS__, 'arrayToXML'), $root);
// set correct headers
\SpoonHTTP::setHeadersByCode($statusCode);
\SpoonHTTP::setHeaders('content-type: text/xml;charset=' . $charset);
// output XML
self::$content = $XML->saveXML();
}