1043 Posts in 379 Topics by 373 members
| Go to End | ||
| Author | Topic: | 1729 Views |
-
Re: nestedurls - upgrade to 2.4.0 breaks old url schema - (possible bug and solution)

15 May 2010 at 3:23am
Ingo, tx for replying
The series are DataObjects, i will post my code below.
The meaning of it all....I stream videos on an Internal Network ( among other stuff i present on the webpage ), so i provide a webpage for people to look trough the series and pick a episode to watch. Everybody loves the way it works ( tx SilverStripe guys ).
Offcourse i could stay with 2.3.7. but i want to move on.....-----------------Code Video--------------------------
class Video extends DataObject {
static $db = array(
'Name' => 'Varchar',
'Server' => 'VarChar',
'Folder' => 'VarChar',
'Omschrijving' => 'Text',
'URLSegment' => 'Varchar(255)');static $has_one = array(
'VideoPage' => 'VideoPage',
'Photo' => 'Image');
static $has_many = array(
'VideoCats' => 'VideoCat',
'VideoStreams' => 'VideoStream');
public function getCMSFields(){
return new FieldSet(
new TextField('Name'),
new TextField('Server'),
new TextField('Folder'),
new TextareaField('Omschrijving'),
new ImageField('Photo', 'COVER'),
new DataObjectManager(
$this,
'VideoCats',
'VideoCat',
array('Name' => 'Naam', )));
}
public function getThumb(){
if($this->PhotoID)
return $this->Photo()->CMSThumbnail();
else
return '(No Photo)';
}
public function getLinkingMode(){
if($this->URLSegment == Director::URLParam('Action')){
return 'current';
}
else{
return 'link';
}
}public function onBeforeWrite(){
if($this->Name){
$this->URLSegment = SiteTree::GenerateURLSegment($this->Name);
if($object = DataObject::get_one($this->ClassName, "URLSegment='".$this->URLSegment."' AND ID !=".$this->ID)){
$this->URLSegment = $this->URLSegment.'-'.$this->ID;
}
} else {
$this->URLSegment = SiteTree::GenerateURLSegment($this->ClassName.'-'.$this->ID);
}
parent::onBeforeWrite();
}
}
---------------------- end of code Video ---------------------------------------- code VideoCat ----------------------
class VideoCat extends DataObject {
static $db = array('Name' => 'Varchar');
static $has_one = array('Video' => 'Video');
static $has_many = array('VideoStreams' => 'VideoStream');
function getCMSFields() {
return new FieldSet(
new TextField('Name', 'Categorie '),
new DataObjectManager(
$this,
'VideoStreams',
'VideoStream',
array('Name'=>'Naam')));
}}
------------------- end of code VideoCat ---------------------------
------------------- code VideoStream --------------------------------
class VideoStream extends DataObject {
static $db = array('Name' => 'Varchar');
static $has_one = array(
'Video'=> 'Video',
'VideoCat' => 'VideoCat');function getCMSFields() {
return new FieldSet(
new TextField('Name', 'exacte naam van het file, ZONDER extensie'));
}
}--------------- end of Code VideoStream --------------------------------
--------------- Code VideoPage -----------------------------------------
class VideoPage extends Page {
static $has_many = array('Videos' => 'Video');
function getCMSFields() {
$fields = parent::getCMSFields();$dataobjectmanager = new HasManyDataObjectManager(
$this,
'Videos',
'Video',
array('Thumb' => 'Photo', 'Name' => 'Name','Server' => 'Server', 'Folder' => 'Folder', 'Omschrijving' => 'Omschrijving'),
'getCMSFields_forPopup'
);
$dataobjectmanager->setPluralTitle("een video");
$fields->addFieldToTab("Root.Content.Video", $dataobjectmanager);
$fields->removeFieldFromTab("Root.Content.Main","Content");
return $fields;
}class VideoPage_Controller extends Page_Controller {
function init(){
parent::init();
Requirements::JavaScript('/mysite/javascript/jquery.min.js');
Requirements::JavaScript('/mysite/javascript/prototype.js');
}
public function getIndividualVideo(){
if($URLAction = Director::URLParam('Action')){$VideoID = Convert::raw2xml($URLAction);
if($VideoID ){
return DataObject::get_one('Video', "URLSegment='".$VideoID."'");
}
}
}
}
---------------------- end of Code VideoPage -------------------------- -
Re: nestedurls - upgrade to 2.4.0 breaks old url schema - (possible bug and solution)

16 May 2010 at 12:38pm
Sorry, that still doesnt explain how you expect your Director rules to work. You must have a Director::addRules() command somewhere to have something like "series/1" work in the first place, right?
-
Re: nestedurls - upgrade to 2.4.0 breaks old url schema - (possible bug and solution)

16 May 2010 at 8:15pm Last edited: 16 May 2010 8:20pm
Tx, but no... i don't use the Director::addRules() command as far as i know. At least i didn't put it anywhere.... But doesn't my Public function 'getindividualVideo' takes care at providing the link.?
ps: You can tell i'm a total beginner at this right? ;)
-
Re: nestedurls - upgrade to 2.4.0 breaks old url schema - (possible bug and solution)

5 August 2010 at 5:44am
I think you're misusing the URL action. Based on your code, you're placing the video ID in the Action param. That doesn't work anymore in 2.4. Actions have to be functions.
So you'll need to create an action like:
function show() {
// get video based on request param "ID"return array (
'Video' => $video
);
}I assume "series" is your URLSegment?
/series/show/123
| 1729 Views | ||
| Go to Top |


