Jump to:

1136 Posts in 1984 Topics by 403 members

Upgrading SilverStripe

SilverStripe Forums » Upgrading SilverStripe » nestedurls - upgrade to 2.4.0 breaks old url schema - (possible bug and solution)

Ask questions about upgrading SilverStripe to the latest version.

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

Page: 1 2
Go to End
Author Topic: 1935 Views
  • Stefdv
    Avatar
    Community Member
    110 Posts

    Re: nestedurls - upgrade to 2.4.0 breaks old url schema - (possible bug and solution) Link to this post

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

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: nestedurls - upgrade to 2.4.0 breaks old url schema - (possible bug and solution) Link to this post

    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?

  • Stefdv
    Avatar
    Community Member
    110 Posts

    Re: nestedurls - upgrade to 2.4.0 breaks old url schema - (possible bug and solution) Link to this post

    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? ;)

  • UncleCheese
    Avatar
    4085 Posts

    Re: nestedurls - upgrade to 2.4.0 breaks old url schema - (possible bug and solution) Link to this post

    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

    1935 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.