Re: Writing to a database from a view
Oh yes thanks to everybody who helped me out on this one... On Jan 16, 8:31 am, "xybersoftw...@gmail.com" wrote: > I moved all of this code into the controller and did queries on the > data instead of if statements in the view and also did the writes to > the database in the controller and it all works. Lesson is you can't > write to the database from the view file... > > On Jan 15, 1:38 am, "xybersoftw...@gmail.com" > > > > wrote: > > Jon, > > Thanks for your detailed help. > > One thing I might not have made clear is that my view/filtering form > > has only one check box and the check box is not connected to each > > record. And I have other fields in the form that let me filter the > > records that I am looking for. Once the user has filtered the records > > he wants to modify, then he finally checks the 'Mark records shown' > > check box and then clicks the submit button to mark only the records > > that are showing with todays date in a date field for each record > > shown. Although Ajax would be nice to have, it is not necessary if I > > can just get the data to show properly after the change with a > > refresh...So I think I need an array of shown records that gets built > > as the records are filtered and then use that array to update the > > records from the controller...So I guess the question now is how do I > > build the data array manually from the view file... > > > view/process_member.thtml > > for () > > { > > if ($chkMark=='1') > > { > > // Mark selected months > > if($chkMonth1=='on') > > //*** If the next line would write to the database it would > > work but it doesn't write to the database > > $subscription['Subscription']['month1_mailinginfo_sent']=date > > ('Y-m-d'); > > // So I guess I need to build an array here and then use that > > in the controller to update the datbase > > //THIS IS WHERE I NEED TO POST BUT NOT SURE HOW TO DO > > THAT?? > > *** > > } > > > On Jan 14, 10:45 pm, "Jon Bennett" wrote: > > > > Hi xybersoftware, > > > > > My form does not have any editable fields... > > > > I only want to change certain fields of the records that are shown in > > > > the view if a user checks a check box and clicks submit... > > > > If the user checks the box then I want to mark all the records that > > > > are shown with todays date... > > > > I guess the question now is how do I post the data from the view so > > > > that in the controller so I can update the database... > > > > if you want to do this _without_ a page refresh, you'll have to do so > > > via an AJAX request. This requires all the same logic and controller > > > code as a normal save from a form, there's no shortcut! > > > > The functions you need are: > > > > controller method which accepts POST data ($this->data) > > > model method which saves POST data > > > prototype/jquery/mootools javascript code to submit the form when a > > > checkbox is changed > > > > in psyudeo code you want to: > > > > * a html page which lists all your items inside a single form > > > * each item in the html page has a checkbox, which has a unique ID and > > > name. The ID of the checkbox should correspond to the record, eg the > > > ID (primary key) of the record > > > * the form submits to a controller method, say > > > /my_controller/update_all_records > > > * this controller method calls a (custom) model method, > > > Model->updateAll($data) > > > * Model->updateAll() loops over the data, and all records that have a > > > checked checkbox are updated > > > * back to your view, you have some javascript which is listening to > > > the 'onchange' event for all your checkboxes > > > * when a checkbox is changed, some more javascript creates a http post > > > request to another controller method, update_record > > > * the controller method calls a corresponding model method, > > > Model->updateRecord($data); > > > * your model method validates the data, and if it's ok and the > > > checkbox is checked, it updates the date field > > > > That's about the size of it - good luck! > > > > Hope this helps > > > > Jon > > > ps: if you don't need a degradable non-javascript version, you can > > > skip all the 'update all records' stuff above > > > > -- > > > > jon bennett > > > w:http://www.jben.net/ > > > iChat (AIM): jbendotnet Skype: jon-bennett- Hide quoted text - > > > - Show quoted text -- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Writing to a database from a view
I moved all of this code into the controller and did queries on the data instead of if statements in the view and also did the writes to the database in the controller and it all works. Lesson is you can't write to the database from the view file... On Jan 15, 1:38 am, "xybersoftw...@gmail.com" wrote: > Jon, > Thanks for your detailed help. > One thing I might not have made clear is that my view/filtering form > has only one check box and the check box is not connected to each > record. And I have other fields in the form that let me filter the > records that I am looking for. Once the user has filtered the records > he wants to modify, then he finally checks the 'Mark records shown' > check box and then clicks the submit button to mark only the records > that are showing with todays date in a date field for each record > shown. Although Ajax would be nice to have, it is not necessary if I > can just get the data to show properly after the change with a > refresh...So I think I need an array of shown records that gets built > as the records are filtered and then use that array to update the > records from the controller...So I guess the question now is how do I > build the data array manually from the view file... > > view/process_member.thtml > for () > { > if ($chkMark=='1') > { > // Mark selected months > if($chkMonth1=='on') > //*** If the next line would write to the database it would > work but it doesn't write to the database > $subscription['Subscription']['month1_mailinginfo_sent']=date > ('Y-m-d'); > // So I guess I need to build an array here and then use that > in the controller to update the datbase > //THIS IS WHERE I NEED TO POST BUT NOT SURE HOW TO DO > THAT?? > *** > } > > On Jan 14, 10:45 pm, "Jon Bennett" wrote: > > > > > Hi xybersoftware, > > > > My form does not have any editable fields... > > > I only want to change certain fields of the records that are shown in > > > the view if a user checks a check box and clicks submit... > > > If the user checks the box then I want to mark all the records that > > > are shown with todays date... > > > I guess the question now is how do I post the data from the view so > > > that in the controller so I can update the database... > > > if you want to do this _without_ a page refresh, you'll have to do so > > via an AJAX request. This requires all the same logic and controller > > code as a normal save from a form, there's no shortcut! > > > The functions you need are: > > > controller method which accepts POST data ($this->data) > > model method which saves POST data > > prototype/jquery/mootools javascript code to submit the form when a > > checkbox is changed > > > in psyudeo code you want to: > > > * a html page which lists all your items inside a single form > > * each item in the html page has a checkbox, which has a unique ID and > > name. The ID of the checkbox should correspond to the record, eg the > > ID (primary key) of the record > > * the form submits to a controller method, say > > /my_controller/update_all_records > > * this controller method calls a (custom) model method, > > Model->updateAll($data) > > * Model->updateAll() loops over the data, and all records that have a > > checked checkbox are updated > > * back to your view, you have some javascript which is listening to > > the 'onchange' event for all your checkboxes > > * when a checkbox is changed, some more javascript creates a http post > > request to another controller method, update_record > > * the controller method calls a corresponding model method, > > Model->updateRecord($data); > > * your model method validates the data, and if it's ok and the > > checkbox is checked, it updates the date field > > > That's about the size of it - good luck! > > > Hope this helps > > > Jon > > ps: if you don't need a degradable non-javascript version, you can > > skip all the 'update all records' stuff above > > > -- > > > jon bennett > > w:http://www.jben.net/ > > iChat (AIM): jbendotnet Skype: jon-bennett- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Writing to a database from a view
Jon, Thanks for your detailed help. One thing I might not have made clear is that my view/filtering form has only one check box and the check box is not connected to each record. And I have other fields in the form that let me filter the records that I am looking for. Once the user has filtered the records he wants to modify, then he finally checks the 'Mark records shown' check box and then clicks the submit button to mark only the records that are showing with todays date in a date field for each record shown. Although Ajax would be nice to have, it is not necessary if I can just get the data to show properly after the change with a refresh...So I think I need an array of shown records that gets built as the records are filtered and then use that array to update the records from the controller...So I guess the question now is how do I build the data array manually from the view file... view/process_member.thtml for () { if ($chkMark=='1') { // Mark selected months if($chkMonth1=='on') //*** If the next line would write to the database it would work but it doesn't write to the database $subscription['Subscription']['month1_mailinginfo_sent']=date ('Y-m-d'); // So I guess I need to build an array here and then use that in the controller to update the datbase //THIS IS WHERE I NEED TO POST BUT NOT SURE HOW TO DO THAT?? *** } On Jan 14, 10:45 pm, "Jon Bennett" wrote: > Hi xybersoftware, > > > My form does not have any editable fields... > > I only want to change certain fields of the records that are shown in > > the view if a user checks a check box and clicks submit... > > If the user checks the box then I want to mark all the records that > > are shown with todays date... > > I guess the question now is how do I post the data from the view so > > that in the controller so I can update the database... > > if you want to do this _without_ a page refresh, you'll have to do so > via an AJAX request. This requires all the same logic and controller > code as a normal save from a form, there's no shortcut! > > The functions you need are: > > controller method which accepts POST data ($this->data) > model method which saves POST data > prototype/jquery/mootools javascript code to submit the form when a > checkbox is changed > > in psyudeo code you want to: > > * a html page which lists all your items inside a single form > * each item in the html page has a checkbox, which has a unique ID and > name. The ID of the checkbox should correspond to the record, eg the > ID (primary key) of the record > * the form submits to a controller method, say > /my_controller/update_all_records > * this controller method calls a (custom) model method, > Model->updateAll($data) > * Model->updateAll() loops over the data, and all records that have a > checked checkbox are updated > * back to your view, you have some javascript which is listening to > the 'onchange' event for all your checkboxes > * when a checkbox is changed, some more javascript creates a http post > request to another controller method, update_record > * the controller method calls a corresponding model method, > Model->updateRecord($data); > * your model method validates the data, and if it's ok and the > checkbox is checked, it updates the date field > > That's about the size of it - good luck! > > Hope this helps > > Jon > ps: if you don't need a degradable non-javascript version, you can > skip all the 'update all records' stuff above > > -- > > jon bennett > w:http://www.jben.net/ > iChat (AIM): jbendotnet Skype: jon-bennett --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Writing to a database from a view
Hi xybersoftware, > My form does not have any editable fields... > I only want to change certain fields of the records that are shown in > the view if a user checks a check box and clicks submit... > If the user checks the box then I want to mark all the records that > are shown with todays date... > I guess the question now is how do I post the data from the view so > that in the controller so I can update the database... if you want to do this _without_ a page refresh, you'll have to do so via an AJAX request. This requires all the same logic and controller code as a normal save from a form, there's no shortcut! The functions you need are: controller method which accepts POST data ($this->data) model method which saves POST data prototype/jquery/mootools javascript code to submit the form when a checkbox is changed in psyudeo code you want to: * a html page which lists all your items inside a single form * each item in the html page has a checkbox, which has a unique ID and name. The ID of the checkbox should correspond to the record, eg the ID (primary key) of the record * the form submits to a controller method, say /my_controller/update_all_records * this controller method calls a (custom) model method, Model->updateAll($data) * Model->updateAll() loops over the data, and all records that have a checked checkbox are updated * back to your view, you have some javascript which is listening to the 'onchange' event for all your checkboxes * when a checkbox is changed, some more javascript creates a http post request to another controller method, update_record * the controller method calls a corresponding model method, Model->updateRecord($data); * your model method validates the data, and if it's ok and the checkbox is checked, it updates the date field That's about the size of it - good luck! Hope this helps Jon ps: if you don't need a degradable non-javascript version, you can skip all the 'update all records' stuff above -- jon bennett w: http://www.jben.net/ iChat (AIM): jbendotnet Skype: jon-bennett --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Writing to a database from a view
submit('Submit!'); ?> Like any other form? Just create a search button and then when you press it, any form data is passed to $this->data in the controller. Try testing it and debugging the data by debug($this->data); Make sure your checkboxes are built using $form. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Writing to a database from a view
My form does not have any editable fields... I only want to change certain fields of the records that are shown in the view if a user checks a check box and clicks submit... If the user checks the box then I want to mark all the records that are shown with todays date... I guess the question now is how do I post the data from the view so that in the controller so I can update the database... PS I am working through the baking test app as you suggested... On Jan 14, 3:36 pm, Webweave wrote: > You will find the data you need in $this->data after the form has > submitted (assuming your form is built correctly and posting to the > right action). > > On Jan 14, 1:39 pm, "xybersoftw...@gmail.com" > > > > wrote: > > Ok got it to write to the database from the controller by hard coding: > > $this->Subscription->saveField('month1_mailinginfo_sent', date('Y-m- > > d')); > > But it added a new blank record with the month filled in...not really > > what I wanted but a baby step forward... > > How do I post from the php code of the view? Also I will probably > > need to POST the id of the record I need to update so when I loop > > through in the controller I know what records to update. I have the > > record id handy in the code so how to post is what I am not > > understanding... > > > view/process_member.thtml > > for () > > { > > if ($chkMark=='1') > > { > > // Mark selected months > > if($chkMonth1=='on') > > $subscription['Subscription']['month1_mailinginfo_sent']=date > > ('Y-m-d'); > > THIS IS WHERE I NEED TO POST BUT NOT SURE HOW TO DO THAT?? > > *** > > } > > > On Jan 14, 12:49 pm, Miles J wrote: > > > > Are you POSTing the data (checked checkboxes) to anywhere? If so loop > > > the $this->data array in the controller.- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Writing to a database from a view
You will find the data you need in $this->data after the form has submitted (assuming your form is built correctly and posting to the right action). On Jan 14, 1:39 pm, "xybersoftw...@gmail.com" wrote: > Ok got it to write to the database from the controller by hard coding: > $this->Subscription->saveField('month1_mailinginfo_sent', date('Y-m- > d')); > But it added a new blank record with the month filled in...not really > what I wanted but a baby step forward... > How do I post from the php code of the view? Also I will probably > need to POST the id of the record I need to update so when I loop > through in the controller I know what records to update. I have the > record id handy in the code so how to post is what I am not > understanding... > > view/process_member.thtml > for () > { > if ($chkMark=='1') > { > // Mark selected months > if($chkMonth1=='on') > $subscription['Subscription']['month1_mailinginfo_sent']=date > ('Y-m-d'); > THIS IS WHERE I NEED TO POST BUT NOT SURE HOW TO DO THAT?? > *** > } > > On Jan 14, 12:49 pm, Miles J wrote: > > > Are you POSTing the data (checked checkboxes) to anywhere? If so loop > > the $this->data array in the controller. > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Writing to a database from a view
I would suggest you run through baking a small app to see how the MVC bits fit together (http://book.cakephp.org/view/113/Code-Generation- with-Bake) The Model is where your data and business logic goes. The Controller handles getting the data from the Model and preparing it for the View. The View handles displaying the data, and interacting with the user. Your process_members.ctp (View) would have a form on it that would submit to the Controller, which would then deal with updating the Model. On Jan 14, 12:40 pm, "xybersoftw...@gmail.com" wrote: > Do it in the controller? I guess that is where I am not > understanding... > How do I get my data from the php code in the thtml file into the > controller? An array_push? > Do I use the save or savefields? Do I need to pass the record id or > index to the controller? > Does my thtml view php interate through the database building up data > for the fields I want changed and then I process the build up in the > the controller save? > I am reading the cake php manual > athttp://book.cakephp.org/view/75/Saving-Your-Data > but still don't quite understand... > Thx for your help > > On Jan 14, 11:04 am, Miles J wrote: > > > Do it in the controller. > > > On Jan 14, 10:39 am, "xybersoftw...@gmail.com" > > > wrote: > > > I have a cake view called process_members.thtml. > > > In the view I have setup some filtering and check boxes. If one of the > > > check boxes is marked I want to write the current date to a field in > > > the database. > > > > So I start Iterating through the database looking at records and so I > > > may be writing to more than one record during this process... > > > > for () > > > { > > > if ($chkMark=='1') > > > { > > > // Mark selected months > > > if($chkMonth1=='on') > > > $subscription['Subscription']['month1_mailinginfo_sent']=date > > > ('Y-m-d'); > > > } > > > > //Then the field is displayed: > > > > > ['month1_mailinginfo_sent']; ?> > > > //The date shows up here but when I go look at the database it has > > > not been written to... > > > > //end for > > > > } > > > > How can I get this date written to the database?- Hide quoted text - > > > - Show quoted text - > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Writing to a database from a view
Ok got it to write to the database from the controller by hard coding: $this->Subscription->saveField('month1_mailinginfo_sent', date('Y-m- d')); But it added a new blank record with the month filled in...not really what I wanted but a baby step forward... How do I post from the php code of the view? Also I will probably need to POST the id of the record I need to update so when I loop through in the controller I know what records to update. I have the record id handy in the code so how to post is what I am not understanding... view/process_member.thtml for () { if ($chkMark=='1') { // Mark selected months if($chkMonth1=='on') $subscription['Subscription']['month1_mailinginfo_sent']=date ('Y-m-d'); THIS IS WHERE I NEED TO POST BUT NOT SURE HOW TO DO THAT?? *** } On Jan 14, 12:49 pm, Miles J wrote: > Are you POSTing the data (checked checkboxes) to anywhere? If so loop > the $this->data array in the controller. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Writing to a database from a view
Are you POSTing the data (checked checkboxes) to anywhere? If so loop the $this->data array in the controller. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Writing to a database from a view
Do it in the controller? I guess that is where I am not understanding... How do I get my data from the php code in the thtml file into the controller? An array_push? Do I use the save or savefields? Do I need to pass the record id or index to the controller? Does my thtml view php interate through the database building up data for the fields I want changed and then I process the build up in the the controller save? I am reading the cake php manual at http://book.cakephp.org/view/75/Saving-Your-Data but still don't quite understand... Thx for your help On Jan 14, 11:04 am, Miles J wrote: > Do it in the controller. > > On Jan 14, 10:39 am, "xybersoftw...@gmail.com" > > > > wrote: > > I have a cake view called process_members.thtml. > > In the view I have setup some filtering and check boxes. If one of the > > check boxes is marked I want to write the current date to a field in > > the database. > > > So I start Iterating through the database looking at records and so I > > may be writing to more than one record during this process... > > > for () > > { > > if ($chkMark=='1') > > { > > // Mark selected months > > if($chkMonth1=='on') > > $subscription['Subscription']['month1_mailinginfo_sent']=date > > ('Y-m-d'); > > } > > > //Then the field is displayed: > > > ['month1_mailinginfo_sent']; ?> > > //The date shows up here but when I go look at the database it has > > not been written to... > > > //end for > > > } > > > How can I get this date written to the database?- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Writing to a database from a view
Do it in the controller. On Jan 14, 10:39 am, "xybersoftw...@gmail.com" wrote: > I have a cake view called process_members.thtml. > In the view I have setup some filtering and check boxes. If one of the > check boxes is marked I want to write the current date to a field in > the database. > > So I start Iterating through the database looking at records and so I > may be writing to more than one record during this process... > > for () > { > if ($chkMark=='1') > { > // Mark selected months > if($chkMonth1=='on') > $subscription['Subscription']['month1_mailinginfo_sent']=date > ('Y-m-d'); > } > > //Then the field is displayed: > ['month1_mailinginfo_sent']; ?> > //The date shows up here but when I go look at the database it has > not been written to... > > //end for > > } > > How can I get this date written to the database? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Writing to a database from a view
I have a cake view called process_members.thtml. In the view I have setup some filtering and check boxes. If one of the check boxes is marked I want to write the current date to a field in the database. So I start Iterating through the database looking at records and so I may be writing to more than one record during this process... for () { if ($chkMark=='1') { // Mark selected months if($chkMonth1=='on') $subscription['Subscription']['month1_mailinginfo_sent']=date ('Y-m-d'); } //Then the field is displayed: //The date shows up here but when I go look at the database it has not been written to... //end for } How can I get this date written to the database? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---