1

So I have seen this error show up, just sometimes, but it is not helpful in describing the actual error which has occured. Nor does it give any clues as to what might cause it to display.

Cannot use modParams with indexes that do not exist.

Can anyone explain more verbosly what this error means, what it relates to (such as a behaviour, component, controller, etc), the most common causes and how to fix it?

To kickstart the investigation, you can find the error here. https://github.com/cakephp/cakephp/blob/master/lib/Cake/Utility/ObjectCollection.php#L128

David Yell
  • 11,756
  • 13
  • 61
  • 100

2 Answers2

2

Layman's Terms
CakePHP is being told to apply an array of parameters to a collection of objects, such that each particular object can modify the parameters sent on to the next object. There is an error in how CakePHP is being told to do this.

In Depth
Generically, this rises from the CakePHP event publication mechanism. Somewhere in your code is an instance of ObjectCollection, which is being triggered with certain parameters. That is, a method is being called on every object in that collection.

Each callback method is given parameters. Originally the parameters are passed into trigger(). In normal cases (where modParams is false), every callback gets the same parameters. But when modParams is not strictly false, the result of each callback overwrites the parameter indicated by modParams.

So if there are two objects in the collection, modParams is 1, and the params[1] is 'a' initially, then the callback is given the first object with params[1] == a. That callback returns 'b', so when the next callback is called, the second object gets params[1] == b.

The exception raises when the modParams value given does not exist in the originally given params. Eg, if modParams is 2 and params is array (0 => 'a', 1 => 'b'), you'll get this exception.

In your case
Specifically, debugging this has to be done at a low-level because it's a method on a generic class. The backtrace from the Exception should get you bubbled up to a trigger() call on a particular concrete class. That call is being given non-false modParams and a params that doesn't have the given modParams. It could be a code bug in a concrete class extending ObjectCollection, or it could simply be a generic message arising from a method not being given expected arguments.

bishop
  • 37,830
  • 11
  • 104
  • 139
  • I don't understand this explanation. I don't pass modParams as an argument to any callback method. Hence asking the question. I was hoping for a more layman's terms explanation. – David Yell Jan 31 '14 at 09:12
  • What part is clear? What part isn't? When I said "somewhere in your code" I did not mean necessarily code you wrote, but rather the whole body of code you're using. An abstract controller for example might be expecting certain incoming parameters to apply to controlled models, but those parameters aren't present and this is the generic message resulting. The best way to offer targeted advice is to see the backtrace. – bishop Jan 31 '14 at 12:38
  • The part which is unclear is `apply an array of parameters to a collection of objects`. The part which is clear is none of it. What is modParams? Where is it set? Are the passed objects models, controllers or views? Is this an upshoot of a bad find, missing table columns, bad callbacks or something else? It's confusing because I am not activly 'trying to use modParams' it's something Cake is doing automatically. I would like to understand that magic to make this error more descriptive of the actual problem occuring. By which I mean the actual object, not the method itsself. – David Yell Jan 31 '14 at 14:21
  • I think the problem I have with this error is that it does not indicate a problem written by a dev. It gives no lead on where to look. Nor does it describe or link to anything the developer knows about in their own app code. It's very generic nature is it's greatest weakness. My question revolves around understanding rather than fixing a code issue. – David Yell Jan 31 '14 at 14:26
  • Forget the specific error & realize it's a problem with an `ObjectCollection`. [CakePHP uses ObjectCollections for lots of things](http://book.cakephp.org/2.0/en/core-libraries/collections.html). So I can't answer any of your general questions because this is a *generic, all-purpose, abstract* class. The most probable cause is that you have, directly or indirectly, a behavior that is calling trigger with inconsistent arguments. I don't know. Without the backtrace, I can't help you specifically. – bishop Jan 31 '14 at 15:19
  • Ah ok, well if it's too broad then I'll vote to close the question as not specific enough. I guess it's generic nature is why the error is so non-descript. – David Yell Jan 31 '14 at 15:36
0

Have you tried reading the documentation?

/*
 * - `modParams` Allows each object the callback gets called on to modify the parameters to the next object.
 *    Setting modParams to an integer value will allow you to modify the parameter with that index.
 *    Any non-null value will modify the parameter index indicated.
 *    Defaults to false.
 */

You did not paste any code, so I guess your 3rd arg of the method contains something wrong.

floriank
  • 25,546
  • 9
  • 42
  • 66
  • I wanted a more generic, basic explanation as the comments don't explain how the method integrates with application code. – David Yell Jan 31 '14 at 09:14