Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Upgrading SilverStripe /

Ask questions about upgrading SilverStripe to the latest version.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

nestedurls - upgrade to 2.4.0 breaks old url schema - (possible bug and solution)


Go to End
Reply


12 Posts   2174 Views

Avatar
Stefdv

Community Member, 110 Posts

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 --------------------------

Avatar
Ingo

Forum Moderator, 801 Posts

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?

Avatar
Stefdv

Community Member, 110 Posts

16 May 2010 at 8:15pm

Edited: 16/05/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? ;)

Avatar
UncleCheese

Forum Moderator, 4096 Posts

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

Go to Top