Where should the (DRY) function to update a Yii model be stored?
===

I have a Yii application with two separate models, *Domain* and *Page*. *Domain* has a unique field, so I set up a rule (`'domain', 'unique'`) and also create an action that creates a new record if the field is new, otherwise uses the existing record, and returns the ID:

	$domain_model=new Domain();
	$domain_model->domain=$domain;
	if(!$domain_model->save()){
		$atts = array('domain'=>$domain);
		$domain_model=Domain::model()->findByAttributes($atts);
	}
	return $domain_model->id;

This works fine, but within a *Page* controller I want to call this same function during a page insertion action. I can't figure out the best DRY method to do this with Yii. I can't access other model controllers, so I don't know where to put this function to make it accessible both within and outside of the *Domain* MVC.