I've completed this using Robby Anderson's suggestions. I found that
it would probably be easiest to create a Notes component to do the
tricker, here is all the code:


---- NOTES COMPONENT

<?php
        class NoteComponent extends Object
        {
                var $note_model = 'Note';
                var $parent_field = 'parent';
                var $parent_id_field = 'parent_id';
                var $text_field = 'text';

                function saveNote($parent,$parent_id,$text)
                {
                        //create a new note object
                if (ClassRegistry::isKeySet($this->note_model))
            {
                    $UserModel =& ClassRegistry::getObject($this-
>note_model);
                }
                else
                {
                loadModel($this->note_model);
                $UserModel =& new $this->note_model;
                }
                        $arr = array($this->note_model =>
                                                        array(
                                                                
$this->parent_field => $parent,
                                                                
$this->parent_id_field => $parent_id,
                                                                
$this->text_field => $text
                                                        )
                                                );
                        $UserModel->save($arr);

                }
        }
?>


--------- NOTES MODEL

<?php
class Note extends AppModel
        {

        var $name = 'Note';

        var $belongsTo = array(
                        'Product' =>
                                array('className' => 'Product',
                                                'foreignKey' => 'parent_id',
                                                'conditions' => "Note.parent = 
'Product'",
                                                'fields' => '',
                                                'order' => '',
                                                'counterCache' => ''
                                ),

                        'Manufacturer' =>
                                array('className' => 'Manufacturer',
                                                'foreignKey' => "Note.parent = 
'Manufacturer'",
                                                'conditions' => '',
                                                'fields' => '',
                                                'order' => '',

'counterCache' => ''
                                ),

        );
}
?>


----- Product model (for example)

class Product extends AppModel {

        var $name = 'Product';

        var $hasMany = array(
                        'Note' =>
                                array('className' => 'Note',
                                                'foreignKey' => 'parent_id',
                                                'conditions' => "Note.parent = 
'Product'",
                                                'fields' => '',
                                                'order' => '',
                                                'limit' => '',
                                                'offset' => '',
                                                'dependent' => '',
                                                'exclusive' => '',
                                                'finderQuery' => '',
                                                'counterQuery' => ''
                                ),
        );

}
?>



Then this can be used very easily from any controller:

        function admin_view($id = null) {
                $this->Note->saveNote('Product',$id,'Product was viewed.');
        }

Make sure to do $components = Array('Note');





I hope this helps someone!


Brian

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to