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.

We've moved the forum!

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.

General Questions /

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

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

Debugging onBeforeWrite Issues


Go to End


718 Views

Avatar
zenmonkey

Community Member, 545 Posts

27 March 2013 at 4:58am

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