Jump to:

23478 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Debugging onBeforeWrite Issues

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 270 Views
  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Debugging onBeforeWrite Issues Link to this post

    I have an onBeforeWrite that will work on new Page creation but not on resaving an existing page, can't figure out why

       function onBeforeWrite() {
          if ( is_null($this->Lat) || is_null($this->Lon) ) {
          
             $LatLon = Geocoder::Geocode($this->Address." ".($this->City()->Title == "Rural Communities" ? $this->Town : $this->City()->Title).", Ontario ".$this->PostalCode);
             
             if($LatLon) {
                
                $this->Lat = $LatLon["Lat"];
                $this->Lon = $LatLon["Lon"];
             }
             
             
          }

          parent::onBeforeWrite();

    I know on the resave the is_null fires true if the field is null, and if I check $this->Lat or $this->Lon before the parent::onBeforeWrite() does show the changed value but it doesn't make it the DB

    270 Views
Page: 1
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.