我们正在使用google sitemap模块:https://github.com/wilr/silverstripe-googlesitemaps
我们有一个TourPage.php
在其控制器上有自定义路由,在sitemap.xml
它显示父页面很好,但没有路由显示:
例如,它只是显示:
website.com/tours/tour-name-1/
website.com/tours/tour-name-2/
但我们希望它显示:
website.com/tours/tour-name-1/
website.com/tours/tour-name-1/photos
website.com/tours/tour-name-1/details
website.com/tours/tour-name-1/reviews
...
website.com/tours/tour-name-2/
website.com/tours/tour-name-2/photos
website.com/tours/tour-name-2/details
website.com/tours/tour-name-2/reviews
等
我们如何实现这一目标?
class TourPage_Controller extends Page_Controller {
private static $allowed_actions = array('BrochureForm', 'brochure', 'brochure_thanks', 'details', 'photos', 'reviews', 'book', 'downloadItineraryFile', 'map', 'overview', 'getSlugName');
public function photos() {
if(!$this->canViewPage()) {
return $this->redirect(ToursPage::getFirstPageLink());
}
return array(
'MetaTitle' => $this->resolveMetaTitle('MetaTitlePhotos'),
'Photos' => $this->TourPhotos(),
'MetaImage' => $this->resolveMetaImagePhotos(),
'MetaVideo' => false,
'ImageSlug' => $this->getSlugName(),
'SluggedImage' => $this->getImageBySlug(),
'AbsolutePhotoURL' => $this->getAbsolutePhotoURL()
);
}
public function index() {
if(!$this->canViewPage()) {
return $this->redirect(ToursPage::getFirstPageLink());
}
// Have to return something...
return array();
}
public function init() {
parent::init();
if($this->request->param('Action') == 'brochure') {
Requirements::themedCSS('bootstrap.min');
Requirements::javascript(THIRD_PARTY_PATH . 'javascript/chosen.jquery.min.js');
}
}
public function overview() {
if(!$this->canViewPage()) {
return $this->redirect(ToursPage::getFirstPageLink());
}
return array();
}
public function details() {
if(!$this->canViewPage()) {
return $this->redirect(ToursPage::getFirstPageLink());
}
// Have to return something...
return array(
'MetaTitle' => $this->resolveMetaTitle('MetaTitleDetails'),
'Photos' => $this->TourPhotos(),
'MetaImage' => $this->resolveMetaImageDetails(),
'MetaVideo' => false
);
}
public function reviews() {
if(!$this->canViewPage()) {
return $this->redirect(ToursPage::getFirstPageLink());
}
return array(
'MetaTitle' => $this->resolveMetaTitle('MetaTitleReviews'),
'Reviews' => $this->data()->Reviews()->Filter('Disabled', 0),
'MetaImage' => $this->resolveMetaImageReviews(),
'MetaVideo' => false
);
}
public function book() {
// If we don't book, then head to the contact page
if($this->ContactFormToBook) {
FlashMessage::add('Please use the Contact Us form if you\'d like to book a ' . $this->Title, 'success');
return $this->redirect(ContactPage::getFirstPageLink());
}
return $this->redirect(BookingPage::getFirstPageLink() . '?Tour=' . $this->ID);
}
/*
* brochure page - with a check to ensure that they are allowed to view the page
*/
public function brochure() {
if(!$this->canViewPage()) {
return $this->redirect(ToursPage::getFirstPageLink());
}
return array();
}
public function map(SS_HTTPRequest $request) {
if(!$this->isAllowedMap()) {
return $this->redirect($this->Link());
}
Requirements::javascript('https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&key=AIzaSyCNCBX_mLK0uuDElVttJVJgM2fuXIynv6E');
Requirements::javascript(THIRD_PARTY_PATH . 'javascript/map.js');
return array(
'MetaImage' => $this->resolveMetaImageMap(),
'MetaVideo' => false
);
}
}
答案 0 :(得分:1)
该模块提供了包含自定义路由的功能,如docs。
中所述以下示例:
GoogleSitemap::register_routes(array(
'/my-custom-controller/',
'/Security/',
'/Security/login/'
));