Relationship between notes and tags
This:

//set the object information
$user_id         =get_current_user_id();
$title           =$this-&gt;input-&gt;post('ui_title_input');
$content_url     =$this-&gt;input-&gt;post('ui_url_input');
$content         =$this-&gt;input-&gt;post('ui_textarea');
$right           =RIGHT_NOTE_PUBLIC;
$status          =STATUS_NOTE_ACTIVE;   

$aNewUserNote-&gt;set_user_id($user_id);
$aNewUserNote-&gt;set_title($title);
$aNewUserNote-&gt;set_content_url($content_url);
$aNewUserNote-&gt;set_content($content);
$aNewUserNote-&gt;set_right($right);
$aNewUserNote-&gt;set_status($status);


Should be rewritten as this

// create and populate note object
$note = new obj_note();           
$note-&gt;set_user_id(get_current_user_id());
$note-&gt;set_title($this-&gt;input-&gt;post('ui_title_input'));
$note-&gt;set_content_url($this-&gt;input-&gt;post('ui_url_input'));
$note-&gt;set_content($this-&gt;input-&gt;post('ui_textarea'));
$note-&gt;set_right(RIGHT_NOTE_PUBLIC);
$note-&gt;set_status(STATUS_NOTE_ACTIVE);


Other than that, my comment on your question will explain the rest.