本文整理汇总了PHP中JApplicationWeb::setHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP JApplicationWeb::setHeader方法的具体用法?PHP JApplicationWeb::setHeader怎么用?PHP JApplicationWeb::setHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JApplicationWeb
的用法示例。
在下文中一共展示了JApplicationWeb::setHeader方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: display
/**
* Display
*
* @return bool
*
* @throws \Exception
* @since 1.7.2
*/
public function display()
{
// Get model data.
$item = $this->get('Item');
$middlename = null;
// Check for errors.
if (count($errors = $this->get('Errors')))
{
Throw new Exception(implode("\n", $errors));
}
JFactory::getDocument()->setMetaData('Content-Type', 'text/directory', true);
// Compute lastname, firstname and middlename
$item->name = trim($item->name);
// "Lastname, Firstname Midlename" format support
// e.g. "de Gaulle, Charles"
$namearray = explode(',', $item->name);
if (count($namearray) > 1)
{
$lastname = $namearray[0];
$card_name = $lastname;
$name_and_midname = trim($namearray[1]);
$firstname = '';
if (!empty($name_and_midname))
{
$namearray = explode(' ', $name_and_midname);
$firstname = $namearray[0];
$middlename = (count($namearray) > 1) ? $namearray[1] : '';
$card_name = $firstname . ' ' . ($middlename ? $middlename . ' ' : '') . $card_name;
}
}
// "Firstname Middlename Lastname" format support
else
{
$namearray = explode(' ', $item->name);
$middlename = (count($namearray) > 2) ? $namearray[1] : '';
$firstname = array_shift($namearray);
$lastname = count($namearray) ? end($namearray) : '';
$card_name = $firstname . ($middlename ? ' ' . $middlename : '') . ($lastname ? ' ' . $lastname : '');
}
$rev = date('c', strtotime($item->modified));
$web = new JApplicationWeb;
$web->setHeader('Content-disposition', 'attachment; filename="' . $card_name . '.vcf"', true);
$vcard = [];
$vcard[] .= 'BEGIN:VCARD';
$vcard[] .= 'VERSION:3.0';
$vcard[] = 'N:' . $lastname . ';' . $firstname . ';' . $middlename;
$vcard[] = 'FN:' . $item->name;
$vcard[] = 'TITLE:' . $item->con_position;
$vcard[] = 'TEL;TYPE=WORK,VOICE:' . $item->telephone;
$vcard[] = 'TEL;TYPE=WORK,FAX:' . $item->fax;
$vcard[] = 'TEL;TYPE=WORK,MOBILE:' . $item->mobile;
$vcard[] = 'ADR;TYPE=WORK:;;' . $item->address . ';' . $item->suburb . ';' . $item->state . ';' . $item->postcode . ';' . $item->country;
$vcard[] = 'LABEL;TYPE=WORK:' . $item->address . "\n" . $item->suburb . "\n" . $item->state . "\n" . $item->postcode . "\n" . $item->country;
$vcard[] = 'EMAIL;TYPE=PREF,INTERNET:' . $item->email_to;
$vcard[] = 'URL:' . $item->webpage;
$vcard[] = 'REV:' . $rev . 'Z';
$vcard[] = 'END:VCARD';
echo implode("\n", $vcard);
return true;
}