Hello Banal
I just edited my last post because I realised that it was very messy
I make it clearer :
I want to adapt your xml technique to a different template :
so I have :
Product.php
<?
class Product extends DataObject
{
static $db = array (
'Productname' => 'Text',
'Presentation' => 'Text',
'Contenance' => 'Text',
'Price' => 'Text'
);
static $has_one = array (
'ProductPage' => 'ProductPage'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Productname'),
new TextField('Presentation'),
new TextField('Contenance'),
new TextField('Price')
//new TextareaField('Quote')
);
}
public function Link() {
return $this->ProductPage()->Link("show/$this->ID");
}
public function FlashVarName() {
return "FlashVarName=$this->Productname";
}
}
then I have ProductPage.php
<?
class ProductPage extends Page
{
static $has_many = array (
'Products' => 'Product'
);
static $db = array(
'ActifsProduct' => 'HTMLText',
'OtherProducts' => 'HTMLText',
'TextProduct' => 'HTMLText',
'GestesProduct' => 'HTMLText',
'SecretProduct' => 'HTMLText',
'ImageName' => 'Text',
'FlashName' => 'Text',
'FlashHeight' => 'Int',
'FlashWidth' => 'Int',
'LayoutType' => 'Text'
);
public function getCMSFields()
{
$f = parent::getCMSFields();
$f->addFieldToTab("Root.Content.Products", new DataObjectManager(
$this,
'Products',
'Product',
array('Productname'=>'Productname','Imagename'=>'Imagename','Presentation' => 'Presentation','Contenance' => 'Contenance','Price' => 'Price'),
'getCMSFields_forPopup'
));
$f->addFieldToTab('Root.Content.ActifsProduct', new HtmlEditorField('ActifsProduct'));
$f->addFieldToTab('Root.Content.OtherProducts', new HtmlEditorField('OtherProducts'));
$f->addFieldToTab('Root.Content.TextProduct', new HtmlEditorField('TextProduct'));
$f->addFieldToTab('Root.Content.GestesProduct', new HtmlEditorField('GestesProduct'));
$f->addFieldToTab('Root.Content.SecretProduct', new HtmlEditorField('SecretProduct'));
$f->addFieldToTab('Root.Content.Main', new TextField('ImageName'), 'Content');
$f->addFieldToTab('Root.Content.Main', new TextField('FlashName'), 'Content');
$f->addFieldToTab('Root.Content.Main', new TextField('FlashWidth'), 'Content');
$f->addFieldToTab('Root.Content.Main', new TextField('FlashHeight'), 'Content');
$f->addFieldToTab('Root.Content.Main', new TextField('LayoutType'), 'Content');
return $f;
}
}
class ProductPage_Controller extends Page_Controller
{
public function index() {
return Director::redirect($this->Products()->First()->Link());
}
public function FlashVar() {
return "myFlashVar=$this->ImageName";
}
public function FlashVarName() {
return "FlashVarName=$this->MenuTitle";
}
static $allowed_actions = array (
'show'
);
public function show() {
return array (
'Product' => DataObject::get_by_id("Product",$this->urlParams['ID'])
);
}
}
and then following your explanations in http://silverstripe.org/template-questions/show/289897?start=0#post290447
I created ExportProductPage_show.ss in export/ folder
since ProductPage_show.ss is my template
Now after flush this what i get :
If I do :
http://mysite/products/productname/show/export
i get the error
user_error("DataObject::get_by_id passed a non-numeric ID #$id", E_USER_WARNING);
If I do :
http://mysite/products/productname/show/5/export
i get the regular page
If I do :
http://mysite/products/productname/export
i get the error :
Action 'export' isn't allowed on class ProductPage_Controller
I hope you can help me because I'm a bit lost ;)
Thanks