本文整理汇总了PHP中Horde_Url::setAnchor方法的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Url::setAnchor方法的具体用法?PHP Horde_Url::setAnchor怎么用?PHP Horde_Url::setAnchor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Horde_Url
的用法示例。
在下文中一共展示了Horde_Url::setAnchor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRemoveEncoded
public function testRemoveEncoded()
{
$url = new Horde_Url('test?foo=1&bar=2');
$this->assertEquals('test?bar=2', (string) $url->remove('foo'));
$url = new Horde_Url('test?foo=1&bar=2');
$this->assertEquals('test?foo=1', (string) $url->remove('bar'));
$url = new Horde_Url('test?foo=1&bar=2');
$this->assertEquals('test', (string) $url->remove(array('foo', 'bar')));
$url = new Horde_Url('test?foo=1&bar=2&baz=3');
$this->assertEquals('test?bar=2&baz=3', (string) $url->remove('foo'));
$url = new Horde_Url('test?foo=1&bar=2#baz');
$url->setAnchor('');
$this->assertEquals('test?foo=1&bar=2', (string) $url);
}
示例2: getUrlFor
/**
* Return a properly formatted link depending on the global pretty url
* configuration
*
* @param string $controller The controller to generate a URL for.
* @param array $data The data needed to generate the URL.
* @param boolean $full Generate a full URL.
* @param integer $append_session 0 = only if needed, 1 = always, -1 = never.
*
* @return Horde_Url The generated URL
*/
public static function getUrlFor($controller, $data, $full = false, $append_session = 0)
{
global $prefs;
$rewrite = isset($GLOBALS['conf']['urls']['pretty']) && $GLOBALS['conf']['urls']['pretty'] == 'rewrite';
switch ($controller) {
case 'view':
if ($rewrite && empty($data['special'])) {
$url = '';
// Viewing a List
if ($data['view'] == 'List') {
$groupby = isset($data['groupby']) ? $data['groupby'] : $prefs->getValue('groupby');
if ($groupby == 'owner' && !empty($data['owner'])) {
$url = 'user/' . urlencode($data['owner']) . '/';
} elseif ($groupby == 'owner') {
$url = 'user/';
} elseif ($groupby == 'none') {
$url = 'all/';
}
$url = Horde::url($url, $full, $append_session);
// don't append the page number if it's zero
if (!empty($data['page'])) {
$url->add('page', $data['page']);
}
return $url;
}
// Viewing a Gallery or Image
if ($data['view'] == 'Gallery' || $data['view'] == 'Image') {
// @TODO: This is needed to correctly generate URLs in
// places that are not specifically requested by the user,
// for instance, in a gallery block. Otherwise, the proper
// date variables would not be attached to the url, since we
// don't know them ahead of time. This is a slight hack and
// needs to be corrected, probably by delegating at least
// some of the URL generation to the gallery/image/view
// object...most likely when we move to PHP5.
if (empty($data['year']) && $data['view'] == 'Image') {
// Getting these objects is not ideal, but at this point
// they should already be locally cached so the cost
// is minimized.
$i = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($data['image']);
$g = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($data['gallery']);
if ($g->get('view_mode') == 'Date') {
$imgDate = new Horde_Date($i->originalDate);
$data['year'] = $imgDate->year;
$data['month'] = $imgDate->month;
$data['day'] = $imgDate->mday;
}
}
$url = 'gallery/' . (!empty($data['slug']) ? $data['slug'] : 'id/' . (int) $data['gallery']) . '/';
// See comments below about lightbox
if ($data['view'] == 'Image' && (empty($data['gallery_view']) || !empty($data['gallery_view']) && $data['gallery_view'] != 'GalleryLightbox')) {
$url .= (int) $data['image'] . '/';
}
$extras = array();
// We may have a value of zero here, but it's the default,
// so ignore it if it's empty.
if (!empty($data['havesearch'])) {
$extras['havesearch'] = $data['havesearch'];
}
// Block any auto navigation (for date views)
if (!empty($data['force_grouping'])) {
$extras['force_grouping'] = $data['force_grouping'];
}
$url = new Horde_Url($url);
if (count($extras)) {
$url->add($extras);
}
//Slight hack until we delegate at least some of the url
// generation to the gallery/image/view object.
if ($data['view'] == 'Image' && !empty($data['gallery_view']) && $data['gallery_view'] == 'GalleryLightbox') {
$url->setAnchor($data['image']);
}
} elseif ($data['view'] == 'Results') {
$url = new Horde_Url('tag/' . (!empty($data['tag']) ? urlencode($data['tag']) . '/' : ''));
if (!empty($data['actionID'])) {
$url->add(array('actionID' => $data['actionID']));
}
if (!empty($data['owner'])) {
$url->add('owner', $data['owner']);
}
}
// Keep the URL as clean as possible - don't append the page
// number if it's zero, which would be the default.
if (!empty($data['page'])) {
$url->add('page', $data['page']);
}
if (!empty($data['year'])) {
$url->add(array('year' => $data['year'], 'month' => empty($data['month']) ? 0 : $data['month'], 'day' => empty($data['day']) ? 0 : $data['day']));
}
//.........这里部分代码省略.........
示例3: testEncodeAnchor
public function testEncodeAnchor()
{
$url = new Horde_Url('test');
$url->setAnchor('a@b.com');
$this->assertEquals('test#a%40b.com', (string) $url);
}