Re: Copying a db record
> nate - I don't understand why it is not considered a bug. I understand > that Cake is intercepting all requests, but why should a request for > favicon.ico be turned into extra requests for the database transaction? Because however you have your controller code setup, the path that is being generated to favicon.ico is mapping to a controller/action that is firing your save action. Is it in a callback, or maybe AppController? However it's happening, it wouldn't happen that way unless your code was setup to make it so. Typing in the URL manually, and having the action that writes the record dump a stack trace (debug_backtrace). Then you should be able to see where and what is being triggered. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Copying a db record
chris - This is a legacy (MS Access) app that I'm transferring, so I was living with the decisions of the prior developer. If I'm not too lazy, I'll probably change the whole sexes thing. nate - I don't understand why it is not considered a bug. I understand that Cake is intercepting all requests, but why should a request for favicon.ico be turned into extra requests for the database transaction? Let's say someone on my design team mistakenly deletes an image file (opr favicon.ico) that is referenced from a view on a production system. Now, instead of a broken image, we are left with database problems, as presumably the actions that called that view are called over and over. That would cause real havoc on a production system... And meanwhile, we would be inclined to troubleshoot the database problem and program logic, instead of looking for a missing image file. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Copying a db record
nannyforum, just out of curiousity, do you have a separate table for Sexes? that's what it looks like, and i'm trying to figure out why. Do you anticipate having to add a third sex when AI is invented or something? :-) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Copying a db record
This isn't a bug in the framework per se. Cake will intercept any HTTP request for a file that doesn't exist in app/webroot, including things like favicons. See here: http://withcake.com/posts/view/watch_your_paths --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Copying a db record
Very interesting indeed! Is this considered a bug? Maybe it ought to be tracked? If correction of this bug isn't possible, maybe it should be placed in somewhere obvious? Will help save a lot of headaches for those unaware - even the veterans. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Copying a db record
What a saga! And the dramatic ending can't be beat. Thank you all for an interesting story. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Copying a db record
Dirk - you were right! First, I replaced the $this->Applicant->save($this->data); line with a direct SQL query, inserting a record. Lo and behold, it inserted 3 records, exactly the same as before. I went to the layout file (I was using the default cakephp layout) and removed the favicon.ico reference. Bingo - only one record gets inserted. I put back the $this->Applicant->save($this->data); line and removed the direct SQL query line - again, it worked flawlessly, with only one insert. So, the question is, why does a separate call to a non-existent favicon.ico file cause CakePHP to execute the controller several times?? Thank you everyone for your help!!! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Copying a db record
Do a LogError('controller action called'); at the top of your controller action and see in app/tmp/logs/error.log, how often the controller action is really called. I had a very similar problem this week and it turned out, that the action was called several times. The source of the problem was, that I had a favicon.ico link in the header that tried to locate a favicon.ico in the actual directory. And due to my route structure, my controller action was called three times. You can also try to use the Firefox Extension "Live HTTP Headers" to find such things. May that helps. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Copying a db record
Hi, Good idea. It doesn't show any warnings, though. And it only shows one INSERT statements as being executed, yet 3 records are still created. 1 DESC `applicants` 32 32 0 2 DESC `divisions`2 2 0 3 DESC `statuses` 2 2 0 4 DESC `schoolyears` 2 2 0 5 DESC `sexes`2 2 0 6 DESC `summerdivisions` 2 2 0 7 DESC `pmprograms` 2 2 0 8 SELECT `Applicant`.`id`, `Applicant`.`schoolyear_id`, `Applicant`.`lastname`, `Applicant`.`firstname`, `Applicant`.`date_entry`, `Applicant`.`date_update`, `Applicant`.`note`, `Applicant`.`status_id`, `Applicant`.`school`, `Applicant`.`grade_apply`, `Applicant`.`division_id`, `Applicant`.`application_date`, `Applicant`.`dob`, `Applicant`.`phone`, `Applicant`.`phone_m_work`, `Applicant`.`phone_f_work`, `Applicant`.`street`, `Applicant`.`city`, `Applicant`.`state`, `Applicant`.`country`, `Applicant`.`zip`, `Applicant`.`nc_parent`, `Applicant`.`nc_street`, `Applicant`.`nc_city`, `Applicant`.`nc_state`, `Applicant`.`nc_country`, `Applicant`.`nc_zip`, `Applicant`.`nickname`, `Applicant`.`sex_id`, `Applicant`.`parent`, `Applicant`.`summerdivision_id`, `Applicant`.`pmprogram_id`, `Division`.`id`, `Division`.`name`, `Status`.`id`, `Status`.`name`, `SchoolYear`.`id`, `SchoolYear`.`name`, `Sex`.`id`, `Sex`.`name`, `SummerDivision`.`id`, `SummerDivision`.`name`, `PMProgram`.`id`, `PMProgram`.`name` FROM `applicants` AS `Applicant` LEFT JOIN `divisions` AS `Division` ON `Applicant`.`division_id` = `Division`.`id` LEFT JOIN `statuses` AS `Status` ON `Applicant`.`status_id` = `Status`.`id` LEFT JOIN `schoolyears` AS `SchoolYear` ON `Applicant`.`schoolyear_id` = `SchoolYear`.`id` LEFT JOIN `sexes` AS `Sex` ON `Applicant`.`sex_id` = `Sex`.`id` LEFT JOIN `summerdivisions` AS `SummerDivision` ON `Applicant`.`summerdivision_id` = `SummerDivision`.`id` LEFT JOIN `pmprograms` AS `PMProgram` ON `Applicant`.`pmprogram_id` = `PMProgram`.`id` WHERE `Applicant`.`id` = '3580' LIMIT 11 1 1 9 INSERT INTO `applicants` (`id`,`schoolyear_id`,`lastname`,`firstname`,`date_entry`,`date_update`,`note`,`status_id`,`school`,`grade_apply`,`division_id`,`application_date`,`dob`,`phone`,`phone_m_work`,`phone_f_work`,`street`,`city`,`state`,`country`,`zip`,`nc_parent`,`nc_street`,`nc_city`,`nc_state`,`nc_country`,`nc_zip`,`nickname`,`sex_id`,`parent`,`summerdivision_id`,`pmprogram_id`) VALUES (NULL,'15','Zoposc','Oscar',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'2',NULL,NULL,NULL) 1 0 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Copying a db record
What is your debug level? Can you turn it to higher and see if there is any warning?I haven't discovered exact cause yet, but I had some problem with excuting same page twicewhen there is session warning about sending header. Just in case.Sohei --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Copying a db record
I tried findById, with the same results. Here's the var_dump of $this->data using either method (read or findById): array(7) { ["Applicant"]=> array(32) { ["id"]=> string(0) "" ["schoolyear_id"]=> int(15) ["lastname"]=> string(6) "Zoposc" ["firstname"]=> string(5) "Oscar" ["date_entry"]=> NULL ["date_update"]=> NULL ["note"]=> NULL ["status_id"]=> NULL ["school"]=> NULL ["grade_apply"]=> NULL ["division_id"]=> NULL ["application_date"]=> NULL ["dob"]=> NULL ["phone"]=> NULL ["phone_m_work"]=> NULL ["phone_f_work"]=> NULL ["street"]=> NULL ["city"]=> NULL ["state"]=> NULL ["country"]=> NULL ["zip"]=> NULL ["nc_parent"]=> NULL ["nc_street"]=> NULL ["nc_city"]=> NULL ["nc_state"]=> NULL ["nc_country"]=> NULL ["nc_zip"]=> NULL ["nickname"]=> NULL ["sex_id"]=> string(1) "2" ["parent"]=> NULL ["summerdivision_id"]=> NULL ["pmprogram_id"]=> NULL } ["Division"]=> array(2) { ["id"]=> NULL ["name"]=> NULL } ["Status"]=> array(2) { ["id"]=> NULL ["name"]=> NULL } ["SchoolYear"]=> array(2) { ["id"]=> string(2) "16" ["name"]=> string(11) "2006 Summer" } ["Sex"]=> array(2) { ["id"]=> string(1) "2" ["name"]=> string(4) "Male" } ["SummerDivision"]=> array(2) { ["id"]=> NULL ["name"]=> NULL } ["PMProgram"]=> array(2) { ["id"]=> NULL ["name"]=> NULL } } --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Copying a db record
what is in the $this->data variable in the copytest function? Is it recursive? I cant remember off the top of my head... does read() return a recursive array? Would using something else like $this->Applicant->findById() possibly fix this? [EMAIL PROTECTED] wrote: > Thanks for keeping at it! > > This option: > $this->Applicant->save(array('Applicant',$this->data['Applicant'])); > didn't make any changes to the database. > > This option: > $this->Applicant->save($this->data); > produced the same results as before, 1 good copy of the record, > sandwiched between 2 new empty records. > > > > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Copying a db record
Thanks for keeping at it! This option: $this->Applicant->save(array('Applicant',$this->data['Applicant'])); didn't make any changes to the database. This option: $this->Applicant->save($this->data); produced the same results as before, 1 good copy of the record, sandwiched between 2 new empty records. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Re: Copying a db record
save takes the associated array either $this->Applicant->save($this->data); or $this->Applicant->save(array('Applicant',$this->data['Applicant')); On 9/15/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Thanks - it has been pasted. > > http://www.cakephp.org/pastes/show/d2e1f32e5bcb2e920a6b1f377027a6a7 > > > > > > -- == S. DeVore (the old fart) the advice is free, the lack of crankiness will cost you --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Copying a db record
Thanks - it has been pasted. http://www.cakephp.org/pastes/show/d2e1f32e5bcb2e920a6b1f377027a6a7 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Copying a db record
Sounds like something else is going wrong. Try pasting your full controller code along with a schema dump of the relevant tables to http://cakephp.org/pastes/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Copying a db record
Again, thanks for the replies guys. I do appreciate the help! Unfortunately, neither strategy worked, although they did show interesting results. Brian's method threw me errors. But Samuel's solution made the following happen: Record 1 remains unchanged. Record 2 created, with the new schoolyear, but no other information was copied from Record 1 (i.e. last name, first name. etc) Record 3 created with new schoolyear, and all information copied from Record 1. (This is the desired result) Record 4 created, with the new schoolyear, but no other information was copied from Record 1 (same as Record 2) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Copying a db record
After you get the record, unset $this->Applicant->id: function copytest($id) { $this->Applicant->id = $id; $this->data = "" unset($this->data['Applicant']['id']); unset($this->Applicant->id = $id;); $this->data['Applicant']['schoolyear_id'] = 16; $this->Applicant->save($this->data['Applicant']); } I didnt test it, but this may help. Brian French [EMAIL PROTECTED] wrote: Thanks for the reply. I tried unsetting the 'id' value, but most strangely, the result is that it changes the original record anyway! I've tried it a dozen times, just to make sure, but that is indeed what is happening. function copytest($id) { $this->Applicant->id = $id; $this->data = "" unset($this->data['Applicant']['id']); $this->data['Applicant']['schoolyear_id'] = 16; $this->Applicant->save($this->data['Applicant']); } If I pass it $id = 1, then it modifies record 1 in the database and sets the schoolyear = 16. If instead, I use this code: function copytest($id) { $this->Applicant->id = $id; $this->data = "" $this->data['Applicant']['id'] = null; $this->data['Applicant']['schoolyear_id'] = 16; $this->Applicant->save($this->data['Applicant']); } It leaves record 1 alone, and creates a copy into record 2 with schoolyear = 16 -- which is exactly what I want, EXCEPT that it also creates copies into record 3 and record 4, both with schoolyear = 16 as well. Any ideas? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Re: Copying a db record
try function copytest($id) { $this->Applicant->id = $id; $this->data = $this->Applicant->read(); $this->Applicant->id = null; unset($this->data['Applicant']['id']); $this->data['Applicant']['schoolyear_id'] = 16; $this->Applicant->save($this->data['Applicant']); } or what I usually do function copytest($id) { $this->Applicant->id = $id; $this->data = $this->Applicant->read(); $this->Applicant->create(); // create a new record for saving unset($this->data['Applicant']['id']); $this->data['Applicant']['schoolyear_id'] = 16; $this->Applicant->save($this->data['Applicant']); } HTH sdevore On 9/15/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Thanks for the reply. > > I tried unsetting the 'id' value, but most strangely, the result is > that it changes the original record anyway! > > I've tried it a dozen times, just to make sure, but that is indeed what > is happening. > > function copytest($id) > { > $this->Applicant->id = $id; > $this->data = $this->Applicant->read(); > unset($this->data['Applicant']['id']); > $this->data['Applicant']['schoolyear_id'] = 16; > > $this->Applicant->save($this->data['Applicant']); > } > > > If I pass it $id = 1, then it modifies record 1 in the database and > sets the schoolyear = 16. > > If instead, I use this code: > > function copytest($id) > { > $this->Applicant->id = $id; > $this->data = $this->Applicant->read(); > $this->data['Applicant']['id'] = null; > $this->data['Applicant']['schoolyear_id'] = 16; > > $this->Applicant->save($this->data['Applicant']); > } > > > It leaves record 1 alone, and creates a copy into record 2 with > schoolyear = 16 -- which is exactly what I want, EXCEPT that it also > creates copies into record 3 and record 4, both with schoolyear = 16 as > well. > > Any ideas? > > > > > -- == S. DeVore (the old fart) the advice is free, the lack of crankiness will cost you --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Copying a db record
Thanks for the reply. I tried unsetting the 'id' value, but most strangely, the result is that it changes the original record anyway! I've tried it a dozen times, just to make sure, but that is indeed what is happening. function copytest($id) { $this->Applicant->id = $id; $this->data = $this->Applicant->read(); unset($this->data['Applicant']['id']); $this->data['Applicant']['schoolyear_id'] = 16; $this->Applicant->save($this->data['Applicant']); } If I pass it $id = 1, then it modifies record 1 in the database and sets the schoolyear = 16. If instead, I use this code: function copytest($id) { $this->Applicant->id = $id; $this->data = $this->Applicant->read(); $this->data['Applicant']['id'] = null; $this->data['Applicant']['schoolyear_id'] = 16; $this->Applicant->save($this->data['Applicant']); } It leaves record 1 alone, and creates a copy into record 2 with schoolyear = 16 -- which is exactly what I want, EXCEPT that it also creates copies into record 3 and record 4, both with schoolyear = 16 as well. Any ideas? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Copying a db record
On 9/14/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: .clippedWhat I want to do is simple - take the original Applicant record (schoolyear = 16) and copy them to a new record, with all the samedata, except that the schoolyear = 15.$this->Applicant->id = $id;$this->data = "" $this->data['Applicant']['id'] = null;$this->data['Applicant']['schoolyear_id'] = 15;$this->Applicant->save($this->data['Applicant']); What I get are three new records, all of them with the schoolyear = 15.The original record remains.Instead of setting the id to null (i.e. $this->data['Applicant']['id'] = null; ) Try doing this...unset( $this->data['Applicant']['id'] );I don't know exactly what the save() code in the model is doing to create 3 entries because I have not looked, but setting the value to null still leaves that entry in the array defined; it is just set to null. Using unset() will actually remove it from the array so that when the data is passed to the save command it will look just like it does when you are adding an entry via a normal "add" form. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---