What about
$this->PersonenPages()->First()->URLSegment
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
What about
$this->PersonenPages()->First()->URLSegment
Whoah! You're fast!
However, no luck :(
[Notice] Trying to get property of non-object
Post your code for the Page and the DataObject.
Code of the Page:
<?php
class PersonenPage extends Page {
static $many_many = array(
'PersonenObjectStandaard' => 'PersonenObject',
'PersonenObjectUitgelicht' => 'PersonenObject'
);
public function getCMSFields() {
$PersonenObjectStandaard = new ManyManyDataObjectManager (
$this,
'PersonenObjectStandaard',
'PersonenObject',
array(
'Name' => 'Naam',
'Function' => 'Functie',
'Notes' => 'Opmerkingen'
),
'getCMSFields_forPopup','',
'Name ASC'
);
$PersonenObjectStandaard->setAddTitle('Personen');
$PersonenObjectStandaard->setSingleTitle('Persoon');
$PersonenObjectUitgelicht = new ManyManyDataObjectManager (
$this,
'PersonenObjectUitgelicht',
'PersonenObject',
array(
'Name' => 'Naam',
'Function' => 'Functie',
'Notes' => 'Opmerkingen'
),
'getCMSFields_forPopup','',
'Name ASC'
);
$PersonenObjectUitgelicht->setAddTitle('Personen');
$PersonenObjectUitgelicht->setSingleTitle('Persoon');
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Personen", new TabSet( "Personen",
new tab('Standaard',new LiteralField('LiF1','<p>Kies hier welke personen weergegeven moeten worden.</p>'), $PersonenObjectStandaard),
new tab('Uitgelicht',new LiteralField('LiF2',"<p>Kies hier enkele personen die met extra nadruk weergegeven moeten worden (deselecteer deze op het tabblad 'Standaard').</p>"),$PersonenObjectUitgelicht)
));
return $fields;
}
}
class PersonenPage_Controller extends Page_Controller {
function view($id = null) {
if($id == null)
$id = $this->urlParams['ID'];
if($id && is_numeric($id))
return DataObject::get_by_id("PersonenObject", $id);
}
}
?>
Code of the DataObject:
<?php
class PersonenObject extends DataObject{
static $db = array(
'Name' => 'Varchar(50)',
'Function' => 'Varchar(50)',
'Address' => 'HTMLText',
'Phone' => 'Varchar(50)',
'Email' => 'Varchar(50)',
'URL' => 'Text',
'Bio' => 'HTMLText',
'Notes' => 'Text',
);
static $has_one = array(
'Image' => 'Image',
);
static $belongs_many_many = array(
'PersonenPage' => 'PersonenPage'
);
function Thumbnail(){
$Image = $this->Image();
if ( $Image ) {
return $Image->CMSThumbnail();
} else {
return null;
}
}
function getCMSFields_forPopup() {
return new FieldSet(
new TextField('Name','Naam'),
new TextField('Function','Functie'),
new TextField('Address','Adres'),
new TextField('Phone','Telefoon'),
new TextField('Email','E-mail (toont een link naar een contactformulier)'),
new TextField('URL','Website'),
new SimpleHTMLEditorField('Bio','Biografie',array(
'css' => 'mysite/css/jquery.wysiwyg.css',
'insertOrderedList' => false,
'insertImage' => false,
'justifyLeft' => false,
'justifyRight' => false,
'justifyCenter' => false,
'cut' => true,
'copy' => true,
'paste' => true,
'html' => true)
),
new myImageField('Image','Portret'),
new TextareaField('Notes','Opmerkingen (worden niet weergegeven op de website)')
);
}
function Link() {
return $this->PersonenPage()->First()->URLSegment . "view/" . $this->ID;
}
}
?>
I got this working...
So I have a holder:
http://pastebin.com/f5106bdce
I create a page in the CMS for that holder.
Now I can:
http://mysite.com/holder/<any text>/12
http://mysite.com/holder/<any text>/100
eg:
http://mysite.com/holder/view/12
http://mysite.com/holder/view/100
http://mysite.com/holder/silverstripe/12
http://mysite.com/holder/silverstripe/100
Note the use us static $song in the function song().
If you don't do that then you will hit the DB for every $song.property in your template.
I did not modify the Song object at all, eg: Overriding Link()
Hi!
I took a look at this and i have a solution which takes the current controller into the url using the SSViewer object.
I dont know if it is the ideal way but it is a solution i think. Maybe some of the Silverstripe devs can take a look at this?
My code:
PersonenPage.php
<?php
class PersonenPage extends Page {
static $many_many = array(
'PersonenObjectStandaard' => 'PersonenObject',
'PersonenObjectUitgelicht' => 'PersonenObject'
);
public function getCMSFields() {
$PersonenObjectStandaard = new ManyManyDataObjectManager (
$this,
'PersonenObjectStandaard',
'PersonenObject',
array(
'Name' => 'Naam',
'Function' => 'Functie',
'Notes' => 'Opmerkingen'
),
'getCMSFields_forPopup','',
'Name ASC'
);
$PersonenObjectStandaard->setAddTitle('Personen');
$PersonenObjectStandaard->setSingleTitle('Persoon');
$PersonenObjectUitgelicht = new ManyManyDataObjectManager (
$this,
'PersonenObjectUitgelicht',
'PersonenObject',
array(
'Name' => 'Naam',
'Function' => 'Functie',
'Notes' => 'Opmerkingen'
),
'getCMSFields_forPopup','',
'Name ASC'
);
$PersonenObjectUitgelicht->setAddTitle('Personen');
$PersonenObjectUitgelicht->setSingleTitle('Persoon');
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Personen", new TabSet( "Personen",
new tab('Standaard',new LiteralField('LiF1','<p>Kies hier welke personen weergegeven moeten worden.</p>'), $PersonenObjectStandaard),
new tab('Uitgelicht',new LiteralField('LiF2',"<p>Kies hier enkele personen die met extra nadruk weergegeven moeten worden (deselecteer deze op het tabblad 'Standaard').</p>"),$PersonenObjectUitgelicht)
));
return $fields;
}
}
class PersonenPage_Controller extends Page_Controller {
public function PersonenList() {
$records = DataObject::get('PersonenObject');
return $records;
}
function view($id = null) {
$params = Director::urlParams();
$id = (int)$params['ID'];
$object = DataObject::get_by_id('PersonenObject',$id);
if($object) {
return $this
->customise(array('DisplayPersoon' => $object))
->renderWith(array('DisplayPersoon', 'Page'));
} else {
Director::redirect(Director::absoluteBaseURL() . 'not-found');
}
}
}
?>
PersonenObject
<?php
class PersonenObject extends DataObject{
static $db = array(
'Name' => 'Varchar(50)',
'Function' => 'Varchar(50)',
'Address' => 'HTMLText',
'Phone' => 'Varchar(50)',
'Email' => 'Varchar(50)',
'URL' => 'Text',
'Bio' => 'HTMLText',
'Notes' => 'Text',
);
static $has_one = array(
'Image' => 'Image',
);
static $belongs_many_many = array(
'PersonenPage' => 'PersonenPage'
);
function Thumbnail(){
$Image = $this->Image();
if ( $Image ) {
return $Image->CMSThumbnail();
} else {
return null;
}
}
function getCMSFields_forPopup() {
return new FieldSet(
new TextField('Name','Naam'),
new TextField('Function','Functie'),
new TextField('Address','Adres'),
new TextField('Phone','Telefoon'),
new TextField('Email','E-mail (toont een link naar een contactformulier)'),
new TextField('URL','Website'),
new SimpleHTMLEditorField('Bio','Biografie',array(
'css' => 'mysite/css/jquery.wysiwyg.css',
'insertOrderedList' => false,
'insertImage' => false,
'justifyLeft' => false,
'justifyRight' => false,
'justifyCenter' => false,
'cut' => true,
'copy' => true,
'paste' => true,
'html' => true)
),
new ImageField('Image','Portret'),
new TextareaField('Notes','Opmerkingen (worden niet weergegeven op de website)')
);
}
function Link() {
return Director::absoluteBaseURL() . SSViewer::topLevel()->URLSegment . "/view/" . $this->ID;
}
}
?>
Deleted by poster