Issue
I need to refresh, reset or unset a model;
Normally, by using a for
operation, the public static $k
value should change, and id does change, but the tableName
model method is called only once;
the value of tablename
will always be 1
, because that is the fisrt value of $i
;
for($i=1;$i<=100;$i++){
VillageBuildingKXSlaveM::$server_id = 1;
VillageBuildingKXSlaveM::$k = $i;
VillageBuildingKXSlaveM::model()->findAllByAttributes(array());
}
<?php
class VillageBuildingKXSlaveM extends VillageBuildingKXM {
public static function model($className = __CLASS__) {
return parent::model($className);
}
public static $server_id;
public static $slave_db;
public static $k;
public function getDbConnection() {
self::$slave_db = Yii::app()->dbx;
if (self::$slave_db instanceof CDbConnection) {
self::$slave_db->active = false;
$config = require(Yii::app()->getBasePath() . '/config/main.php');
$connectionString = $config['components']['dbx']['connectionString'];
self::$slave_db->connectionString = sprintf($connectionString, self::$server_id);
self::$slave_db->setActive(true);
return self::$slave_db;
} else
throw new CDbException(Yii::t('yii', 'Active Record requires a "db" CDbConnection application component.'));
}
public function tableName() {
return 'village_building_k' . self::$k;
}
}
Solution
Try using
VillageBuildingKXSlaveM::model()->unsetAttributes();
to unset the attributes in a model Or you can also pass the attributes name as arguments in the method like
VillageBuildingKXSlaveM::model()->unsetAttributes($attributes);
Answered By - Let me see
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.