AR问题 Qiang请进

Photo::model()->updateAll(

        array(


            'indexof'=>'indexof=indexof+1'


        ), $condition, $params);

我需要在后面加上 运算 如何实现 这样会打出 indexof=‘indexof=index+1’

你可以用updateCounters().

另外,你也可以考虑用CDbExpression:

Photo::model()->updateAll(array(‘indexof’=>new CDbExpression(‘indexof=indexof+1’)) …)

对你这个特定的问题,updateCounters()是推荐的用法

updateCounters 给个例子 看下

Post::model()->updateCounters(array(‘indexof’=>1));

其实API的描述已经足够了:

http://www.yiiframework.com/doc/api/CActiveRecord#updateCounters-detail