Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving form with 2.4.2 generates loop error #9

Open
sergeydeg opened this issue Dec 19, 2013 · 6 comments
Open

Saving form with 2.4.2 generates loop error #9

sergeydeg opened this issue Dec 19, 2013 · 6 comments
Milestone

Comments

@sergeydeg
Copy link

Fatal error: Maximum function nesting level of '100' reached, aborting! in E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php on line 101

Call Stack:
0.0003 361544 1. {main}() E:\htdocs\cakephp2\app\webroot\index.php:0
0.0158 3221736 2. Dispatcher->dispatch() E:\htdocs\cakephp2\app\webroot\index.php:110
0.0227 4338536 3. Dispatcher->_invoke() E:\htdocs\cakephp2\lib\Cake\Routing\Dispatcher.php:162
0.0254 4683528 4. Controller->invokeAction() E:\htdocs\cakephp2\lib\Cake\Routing\Dispatcher.php:187
0.0254 4684112 5. ReflectionMethod->invokeArgs() E:\htdocs\cakephp2\lib\Cake\Controller\Controller.php:490
0.0254 4684128 6. GroupsController->edit() E:\htdocs\cakephp2\lib\Cake\Controller\Controller.php:490
0.0438 8098488 7. Model->save() E:\htdocs\cakephp2\app\Controller\GroupsController.php:52
0.0443 8102496 8. Model->validates() E:\htdocs\cakephp2\lib\Cake\Model\Model.php:1738
0.0451 8254496 9. ModelValidator->validates() E:\htdocs\cakephp2\lib\Cake\Model\Model.php:3297
0.0451 8254496 10. ModelValidator->errors() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:101
0.0451 8254496 11. ModelValidator->_triggerBeforeValidate() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:243
0.0453 8267800 12. CakeEventManager->dispatch() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:459
0.0454 8268048 13. call_user_func() E:\htdocs\cakephp2\lib\Cake\Event\CakeEventManager.php:248
0.0454 8268064 14. ObjectCollection->trigger() E:\htdocs\cakephp2\lib\Cake\Event\CakeEventManager.php:248
0.0454 8270280 15. call_user_func_array() E:\htdocs\cakephp2\lib\Cake\Utility\ObjectCollection.php:132
0.0454 8270296 16. MultiTranslateBehavior->beforeValidate() E:\htdocs\cakephp2\lib\Cake\Utility\ObjectCollection.php:132
0.0454 8270328 17. MultiTranslateBehavior->_multiValidate() E:\htdocs\cakephp2\app\Model\Behavior\MultiTranslateBehavior.php:146
0.0454 8274176 18. Model->validates() E:\htdocs\cakephp2\app\Model\Behavior\MultiTranslateBehavior.php:230
0.0454 8274176 19. ModelValidator->validates() E:\htdocs\cakephp2\lib\Cake\Model\Model.php:3297
0.0454 8274176 20. ModelValidator->errors() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:101
0.0454 8274176 21. ModelValidator->_triggerBeforeValidate() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:243
0.0454 8275000 22. CakeEventManager->dispatch() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:459
0.0455 8275248 23. call_user_func() E:\htdocs\cakephp2\lib\Cake\Event\CakeEventManager.php:248
0.0455 8275264 24. ObjectCollection->trigger() E:\htdocs\cakephp2\lib\Cake\Event\CakeEventManager.php:248
0.0455 8277512 25. call_user_func_array() E:\htdocs\cakephp2\lib\Cake\Utility\ObjectCollection.php:132
0.0455 8277528 26. MultiTranslateBehavior->beforeValidate() E:\htdocs\cakephp2\lib\Cake\Utility\ObjectCollection.php:132
0.0455 8277560 27. MultiTranslateBehavior->_multiValidate() E:\htdocs\cakephp2\app\Model\Behavior\MultiTranslateBehavior.php:146
0.0455 8281408 28. Model->validates() E:\htdocs\cakephp2\app\Model\Behavior\MultiTranslateBehavior.php:230
0.0455 8281408 29. ModelValidator->validates() E:\htdocs\cakephp2\lib\Cake\Model\Model.php:3297
0.0455 8281408 30. ModelValidator->errors() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:101
0.0455 8281408 31. ModelValidator->_triggerBeforeValidate() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:243
0.0455 8282232 32. CakeEventManager->dispatch() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:459
0.0455 8282480 33. call_user_func() E:\htdocs\cakephp2\lib\Cake\Event\CakeEventManager.php:248
0.0455 8282496 34. ObjectCollection->trigger() E:\htdocs\cakephp2\lib\Cake\Event\CakeEventManager.php:248
0.0456 8284744 35. call_user_func_array() E:\htdocs\cakephp2\lib\Cake\Utility\ObjectCollection.php:132
0.0456 8284760 36. MultiTranslateBehavior->beforeValidate() E:\htdocs\cakephp2\lib\Cake\Utility\ObjectCollection.php:132
0.0456 8284792 37. MultiTranslateBehavior->_multiValidate() E:\htdocs\cakephp2\app\Model\Behavior\MultiTranslateBehavior.php:146
0.0456 8288640 38. Model->validates() E:\htdocs\cakephp2\app\Model\Behavior\MultiTranslateBehavior.php:230
0.0456 8288640 39. ModelValidator->validates() E:\htdocs\cakephp2\lib\Cake\Model\Model.php:3297
0.0456 8288640 40. ModelValidator->errors() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:101
0.0456 8288640 41. ModelValidator->_triggerBeforeValidate() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:243
0.0456 8289464 42. CakeEventManager->dispatch() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:459
0.0456 8289712 43. call_user_func() E:\htdocs\cakephp2\lib\Cake\Event\CakeEventManager.php:248
0.0456 8289728 44. ObjectCollection->trigger() E:\htdocs\cakephp2\lib\Cake\Event\CakeEventManager.php:248
0.0456 8292064 45. call_user_func_array() E:\htdocs\cakephp2\lib\Cake\Utility\ObjectCollection.php:132
0.0456 8292080 46. MultiTranslateBehavior->beforeValidate() E:\htdocs\cakephp2\lib\Cake\Utility\ObjectCollection.php:132
0.0456 8292112 47. MultiTranslateBehavior->_multiValidate() E:\htdocs\cakephp2\app\Model\Behavior\MultiTranslateBehavior.php:146
0.0457 8295960 48. Model->validates() E:\htdocs\cakephp2\app\Model\Behavior\MultiTranslateBehavior.php:230
0.0457 8295960 49. ModelValidator->validates() E:\htdocs\cakephp2\lib\Cake\Model\Model.php:3297
0.0457 8295960 50. ModelValidator->errors() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:101
0.0457 8295960 51. ModelValidator->_triggerBeforeValidate() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:243
0.0457 8296784 52. CakeEventManager->dispatch() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:459
0.0457 8297032 53. call_user_func() E:\htdocs\cakephp2\lib\Cake\Event\CakeEventManager.php:248
0.0457 8297048 54. ObjectCollection->trigger() E:\htdocs\cakephp2\lib\Cake\Event\CakeEventManager.php:248
0.0457 8299384 55. call_user_func_array() E:\htdocs\cakephp2\lib\Cake\Utility\ObjectCollection.php:132
0.0457 8299400 56. MultiTranslateBehavior->beforeValidate() E:\htdocs\cakephp2\lib\Cake\Utility\ObjectCollection.php:132
0.0457 8299432 57. MultiTranslateBehavior->_multiValidate() E:\htdocs\cakephp2\app\Model\Behavior\MultiTranslateBehavior.php:146
0.0457 8303280 58. Model->validates() E:\htdocs\cakephp2\app\Model\Behavior\MultiTranslateBehavior.php:230
0.0457 8303280 59. ModelValidator->validates() E:\htdocs\cakephp2\lib\Cake\Model\Model.php:3297
0.0457 8303280 60. ModelValidator->errors() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:101
0.0457 8303280 61. ModelValidator->_triggerBeforeValidate() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:243
0.0458 8304104 62. CakeEventManager->dispatch() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:459
0.0458 8304352 63. call_user_func() E:\htdocs\cakephp2\lib\Cake\Event\CakeEventManager.php:248
0.0458 8304368 64. ObjectCollection->trigger() E:\htdocs\cakephp2\lib\Cake\Event\CakeEventManager.php:248
0.0458 8306704 65. call_user_func_array() E:\htdocs\cakephp2\lib\Cake\Utility\ObjectCollection.php:132
0.0458 8306720 66. MultiTranslateBehavior->beforeValidate() E:\htdocs\cakephp2\lib\Cake\Utility\ObjectCollection.php:132
0.0458 8306752 67. MultiTranslateBehavior->_multiValidate() E:\htdocs\cakephp2\app\Model\Behavior\MultiTranslateBehavior.php:146
0.0458 8310600 68. Model->validates() E:\htdocs\cakephp2\app\Model\Behavior\MultiTranslateBehavior.php:230
0.0458 8310600 69. ModelValidator->validates() E:\htdocs\cakephp2\lib\Cake\Model\Model.php:3297
0.0458 8310600 70. ModelValidator->errors() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:101
0.0458 8310600 71. ModelValidator->_triggerBeforeValidate() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:243
0.0458 8311424 72. CakeEventManager->dispatch() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:459
0.0459 8311672 73. call_user_func() E:\htdocs\cakephp2\lib\Cake\Event\CakeEventManager.php:248
0.0459 8311688 74. ObjectCollection->trigger() E:\htdocs\cakephp2\lib\Cake\Event\CakeEventManager.php:248
0.0459 8314024 75. call_user_func_array() E:\htdocs\cakephp2\lib\Cake\Utility\ObjectCollection.php:132
0.0459 8314040 76. MultiTranslateBehavior->beforeValidate() E:\htdocs\cakephp2\lib\Cake\Utility\ObjectCollection.php:132
0.0459 8314072 77. MultiTranslateBehavior->_multiValidate() E:\htdocs\cakephp2\app\Model\Behavior\MultiTranslateBehavior.php:146
0.0459 8317920 78. Model->validates() E:\htdocs\cakephp2\app\Model\Behavior\MultiTranslateBehavior.php:230
0.0459 8317920 79. ModelValidator->validates() E:\htdocs\cakephp2\lib\Cake\Model\Model.php:3297
0.0459 8317920 80. ModelValidator->errors() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:101
0.0459 8317920 81. ModelValidator->_triggerBeforeValidate() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:243
0.0459 8318744 82. CakeEventManager->dispatch() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:459
0.0459 8318992 83. call_user_func() E:\htdocs\cakephp2\lib\Cake\Event\CakeEventManager.php:248
0.0459 8319008 84. ObjectCollection->trigger() E:\htdocs\cakephp2\lib\Cake\Event\CakeEventManager.php:248
0.0460 8321344 85. call_user_func_array() E:\htdocs\cakephp2\lib\Cake\Utility\ObjectCollection.php:132
0.0460 8321360 86. MultiTranslateBehavior->beforeValidate() E:\htdocs\cakephp2\lib\Cake\Utility\ObjectCollection.php:132
0.0460 8321392 87. MultiTranslateBehavior->_multiValidate() E:\htdocs\cakephp2\app\Model\Behavior\MultiTranslateBehavior.php:146
0.0460 8325240 88. Model->validates() E:\htdocs\cakephp2\app\Model\Behavior\MultiTranslateBehavior.php:230
0.0460 8325240 89. ModelValidator->validates() E:\htdocs\cakephp2\lib\Cake\Model\Model.php:3297
0.0460 8325240 90. ModelValidator->errors() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:101
0.0460 8325240 91. ModelValidator->_triggerBeforeValidate() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:243
0.0460 8326064 92. CakeEventManager->dispatch() E:\htdocs\cakephp2\lib\Cake\Model\ModelValidator.php:459
0.0460 8326312 93. call_user_func() E:\htdocs\cakephp2\lib\Cake\Event\CakeEventManager.php:248
0.0460 8326328 94. ObjectCollection->trigger() E:\htdocs\cakephp2\lib\Cake\Event\CakeEventManager.php:248
0.0460 8328664 95. call_user_func_array() E:\htdocs\cakephp2\lib\Cake\Utility\ObjectCollection.php:132
0.0460 8328680 96. MultiTranslateBehavior->beforeValidate() E:\htdocs\cakephp2\lib\Cake\Utility\ObjectCollection.php:132
0.0461 8328712 97. MultiTranslateBehavior->_multiValidate() E:\htdocs\cakephp2\app\Model\Behavior\MultiTranslateBehavior.php:146
0.0461 8332560 98. Model->validates() E:\htdocs\cakephp2\app\Model\Behavior\MultiTranslateBehavior.php:230
0.0461 8332560 99. ModelValidator->validates() E:\htdocs\cakephp2\lib\Cake\Model\Model.php:3297

@sergeydeg sergeydeg reopened this Dec 19, 2013
@savedario
Copy link

I think I had the same problem with cakePHP 2.3 because of the way validation is done from 2.3 onward.
I had to develop a patch, unfortunately not limited to the MultiTranslateBehaviour code, to make it work.

@zoghal
Copy link
Owner

zoghal commented Dec 19, 2013

This plugin is for 2.1+ require little change,
please use this code:

pr($this->request->data)

I know what you want to save

@sergeydeg
Copy link
Author

Array
(
[Group] => Array
(
[description] => Array
(
[rus] => Сухие корма
[lav] => Sausa barība
)

        [Group_ID] => 12
        [Group_Parent_ID] => 2
    )

)

class Group extends AppModel {
public $name = 'Group';
public $useTable = 'groups';
public $primaryKey = 'Group_ID';
public $order = array("Group.Group_Parent_ID" => "asc", "Group.Group_ID" => "asc");
public $actsAs = array(
'MultiTranslate' => array(
'description'
)
);
public $validate = array(
'description' => array(
'rule' => 'notEmpty',
'required' => true,
'message' => 'Group Name mus be set!'
)
);
}

public function edit($groupid = null){
if (!$groupid) {
throw new NotFoundException(__('Invalid group'));
}
$this->Group->setLocale(array('rus','lav'));

    if (!$this->Group->exists($groupid)) {
        throw new NotFoundException(__('Invalid group'));
    }
    $this->Group->multiTranslateOptions(array('validate'=>true,'find'=>true));
    if ($this->request->is(array('post','put'))){
        $this->Group->Group_ID = $groupid;
        pr($this->request->data);
        if ($this->Group->save($this->request->data)) {
            $this->Session->setFlash(__('Group saved'));

            return;
        }
        $this->Session->setFlash(__('Unable to save group'));
    }
    if (!$this->request->data) {
        $this->request->data = $this->Group->read(null,$groupid);
    }
}

@zoghal
Copy link
Owner

zoghal commented Dec 20, 2013

@sergeydeg In fact, I can not guess what the problem is .. this is for cake 2.1. And he has a lot of problems.
Please file error.log / debug.log see which line is currently getting an error.

@sergeydeg
Copy link
Author

Actually problem is, IMHO in logic change in CakePHP since 2.1. I started using it only with newest version, but what I see, that Model::Save call Model::Validates (line 8 in stacktrace), then callback BeforeValidate fired witch going through to MultiTranslateBehavior->multiValidate() (line 17) , and then that again call Model->validates() (line 18) creating an infinitive loop.

@Erwane
Copy link

Erwane commented Mar 7, 2014

Any news about this issues on CakePHP 2.4 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants