0

This must be something ugly obvious, but I'm stucked on this and can't solve it for past two hours.

I have this piece of code:

foreach($idMap as $menuId=>$pageId)
{
    echo('$this->update("menus_items", SET "link = /content/show?id='.$pageId.'" WHERE id = '.$menuId.');'."\n");

    $this->update
    (
        'menus_items',
        array('link'=>'/content/show?id='.$pageId),
        array('id = '.$menuId)
    );
}

echo part works as expected ($pageId is different for each item, taken from $idMap), while Yii's CDbCommand::update() gets wako and have $pageId equal to it's last value for all loop iterations.

In other words, if I have 20 menu items and last item in result set has pageId = 18, then when using CDbCommand::update(), I'm getting all menu items set to that last value.

There must be some variable overwriting here, but I can't find it for past two hours, especially, that echo put just one line above works great. Can someone help here.

trejder
  • 17,148
  • 27
  • 124
  • 216
  • 1
    we cannot see what `$this->update` does. I cannot see any overwriting. The error must be somewhere else. – steven Mar 13 '15 at 16:41
  • What is `$this`? CActiveRecord? – hamed Mar 13 '15 at 16:51
  • @steven Thanks for attempting to help. It seems, that this problem must be somehow related to Yii. I'll ask at their forum. If I'll get some valuable answers there, I'll consider reposting them here. Thanks for double checking and assuring me, that I'm not missing something stupid. – trejder Mar 13 '15 at 19:20
  • @hamed As I wrote in my question, we're talking about `CDbCommand::update()`. Therefore, `$this` is `CDbCommand`, not `CActiveRecord`. – trejder Mar 13 '15 at 19:21

1 Answers1

2

Guessing, but does $this->update() expect a single array for its bind arguments?

$this->update
    (
        'menus_items',
        array(
            'link' => '/content/show?id='.$pageId,
            'id' => $menuId
        )
    );
Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • Thanks for attempting to help. It seems, that this problem must be somehow related to Yii. I'll ask at their forum. If I'll get some valuable answers there, I'll consider reposting them here. Thanks for double checking and assuring me, that I'm not missing something stupid. – trejder Mar 13 '15 at 19:20