I have a model Tags, I want to add a function in Tags model, that check if tag exists, if not creat a new record and return an id, but how do I save it within itself's model, do I need to initialize an instance?
class Tags extends Model{
public function loadTag($string){
$exist = self::findFirst(array(
'name'=>$string,
));
if($exist){
return $exist->id;
}else{
//How to create a new record here within Tag model?
//is it best to do with $tag = new Tags();?
}
}
}