Re: Log controller
I would setup the notes one of two ways: id parent parent_id text created Where parent = the model name you want to link to and parent_id is the foreign key. This allows you to link to any model that you want to, instead of just the ones you listed, and is a bit better design. (I'd also add a user_id column to link to the adding user.) However, this always limits a note to a single entity. You can also create notes with two tables: id text created and a second note_parent table id note_id parent parent_id Again, where parent = the model name you want to link to and parent_id is the foreign key. (And again, I'd add a user_id to the notes table.) This allows you to link a single note to multiple models (much like tags). As for auto-creating a note on certain actions, why note just instantiate a note object, pass it the data you want to save and save it right then and there? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Log controller
How would you instantiate a note object? Can you please give me an example? Thanks. Brian On Jan 7, 8:28 pm, Robby Anderson [EMAIL PROTECTED] wrote: I would setup the notes one of two ways: id parent parent_id text created Where parent = the model name you want to link to and parent_id is the foreign key. This allows you to link to any model that you want to, instead of just the ones you listed, and is a bit better design. (I'd also add a user_id column to link to the adding user.) However, this always limits a note to a single entity. You can also create notes with two tables: id text created and a second note_parent table id note_id parent parent_id Again, where parent = the model name you want to link to and parent_id is the foreign key. (And again, I'd add a user_id to the notes table.) This allows you to link a single note to multiple models (much like tags). As for auto-creating a note on certain actions, why note just instantiate a note object, pass it the data you want to save and save it right then and there? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Log controller
I think you will find that the system is more maintainable if you simply add a notes column to the Products, Manufacturers and Users tables. On Jan 7, 7:53 pm, brian_gaff [EMAIL PROTECTED] wrote: Hi, I have a website that is basically a shopping cart. It has Products, Manufactures, Users, etc. I've added a 'Notes' controller with the following fields: id user_id product_id manufacturer_id text The idea is that I can set the respective foreign key so that I can use the notes controller to add notes to any object. Is this the correct way to do it? My next question is, I want to automatically add a note when an administrator does certain tasks, eg, modify a user account. I was thinking about using the $controller-requestAction(), however, if the note is fairly long it will be kind of weird to do this: /* this is just psuedo code, I do not actually store session information like this */ $ses = $this-Session-read('currentUser'); $note = User account was suspended by {$ses['User']['username']}; $this-requestAction('/admin/notes/add/' . $note); It would seem weird to request an action with spaced text like that. Is there another way to do it, i guess what I'm asking is... requestAction is like GET, is there another way that's similiar to a POST. Is it safe to do what I want to do this way? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Log controller
But each Product, User, Manufacturer, Bid, Etc, hasMany Notes... On Jan 7, 8:29 pm, aranworld [EMAIL PROTECTED] wrote: I think you will find that the system is more maintainable if you simply add a notes column to the Products, Manufacturers and Users tables. On Jan 7, 7:53 pm, brian_gaff [EMAIL PROTECTED] wrote: Hi, I have a website that is basically a shopping cart. It has Products, Manufactures, Users, etc. I've added a 'Notes' controller with the following fields: id user_id product_id manufacturer_id text The idea is that I can set the respective foreign key so that I can use the notes controller to add notes to any object. Is this the correct way to do it? My next question is, I want to automatically add a note when an administrator does certain tasks, eg, modify a user account. I was thinking about using the $controller-requestAction(), however, if the note is fairly long it will be kind of weird to do this: /* this is just psuedo code, I do not actually store session information like this */ $ses = $this-Session-read('currentUser'); $note = User account was suspended by {$ses['User']['username']}; $this-requestAction('/admin/notes/add/' . $note); It would seem weird to request an action with spaced text like that. Is there another way to do it, i guess what I'm asking is... requestAction is like GET, is there another way that's similiar to a POST. Is it safe to do what I want to do this way? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Log controller
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 -~--~~~~--~~--~--~---
Re: Log controller
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 -~--~~~~--~~--~--~---