21493 Posts in 5784 Topics by 2622 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 852 Views |
-
Special .ss Template for XML Version of Page

24 August 2010 at 1:27pm
HTML versions of page on my website can be accessed at URLs like this:
/page/I also want each page to be available in XML format at URLs like this:
/page.xmlNow "Page.ss" is used as the HTML template.
I want "PageXML.ss" should be used as the template for the XML version of pages.
-
Re: Special .ss Template for XML Version of Page

25 August 2010 at 6:48pm
Shouldn't be too difficult.
First you need a special rewrite-rule:<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*)\.xml$ sapphire/main.php?url=$1/xml [L,QSA]
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
</IfModule>The red part is what's newly added.
Then add the following function to your Page_Controller:
public function xml(){
return array();
}And now all that is left to do is to create a special template for that. You have to name it Page_xml.ss and put it in your templates folder.
Calling /page.xml?flush=1 should now render your page with the XML template.
-
Re: Special .ss Template for XML Version of Page

14 June 2011 at 12:37am
Hi Bana,
I am sorry to disturb you, I was trying to generate the record from DataObject into XML format for using on my flash page.
I have NewsItem as DataObject with following code:--------------------------------------------------------------
NewsItem.php
-------------------------------------------------------------
class NewsItem extends DataObject {static $db = array(
'Title' => 'Varchar(255)',
'Details' => 'HTMLText',
'Source' => 'Varchar(255)',
'Date' => 'Date'
);
static $has_one = array(
'NewsPage' => 'NewsPage',
'NewsPhoto' => 'Image'
);
static $summary_fields = array(
'Title' => 'Title',
'Source' => 'Source',
'Date' => 'Date'
);public function getCMSFields() {
return new FieldSet(
new TextField('Title'),
new SimpleTinyMCEField('Details', 'News Details'),
new TextField('Source', 'News Source'),
new DatePickerField('Date', 'Release Date'),
new ImageField('NewsPhoto', 'Photo', Null, Null, Null, 'Uploads/latest-news/photos/')
);
}function caView() {
return true;
}//Return the Name as a menu title
public function MenuTitle() {
return $this->Title;
}public function Link() {
if ($NewsPage = $this->NewsPage()) {
return $NewsPage->Link('show/') . $this->ID;
}
}public function LinkingMode() {
if ($Controller = Controller::CurrentPage() && Controller::CurrentPage()->ClassName == 'NewsPage') {
if (Controller::CurrentPage()->getAction() == 'show' && $NewsItem = Controller::CurrentPage()->getNewsItem()) {
return ($NewsItem->ID == $this->ID) ? 'current' : 'link';
}
}
}}
----------------------------my purpose i would like to generate all record from this DataObject into XML Format, you have any example, I am trying many way but it return 404 error.
Your replies I really appreciated.
Bunheng
| 852 Views | ||
|
Page:
1
|
Go to Top |


