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.

General Questions /

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

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

Debugging onBeforeWrite Issues


Go to End
Reply


434 Views

Avatar
zenmonkey

Community Member, 541 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