Hi all,
I used gii to create a model of a database table. Here is the table definition:
CREATE TABLE `omega_activemove` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`rigid` int(11) NOT NULL ,
`x` float NULL ,
`y` float NULL ,
`speed` float NOT NULL DEFAULT '0',
`resourcenodeid` int(11) DEFAULT NULL,
`salvageid` int(11) DEFAULT NULL,
PRIMARY KEY(`id`),
UNIQUE KEY(`rigid`),
KEY `activemovern_ref` (`resourcenodeid`),
KEY `activemovesrig_ref` (`salvageid`),
KEY `activemoverig_ref` (`rigid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
The header of the CActiveRecord looks like this:
/**
* This is the model class for table "{{activemove}}".
*
* The followings are the available columns in table '{{activemove}}':
* @property integer $id
* @property integer $rigid
* @property double $x
* @property double $y
* @property double $speed
* @property integer $resourcenodeid
* @property integer $salvageid
*
* The followings are the available model relations:
* @property Resourcemap $resourcenode
* @property Rig $salvage
* @property Rig $rig
*/
I wrote some code where it gets all the rows of this table and processes each one. At one point I call another function sending the rigid property. In the subsequent function I check to see if it is an integer by using is_int(). It returns false. When I echo the value, it is the number 1 (one).
Here is the looping function and the first part of the called function:
public function moveLoop () {
// Run through active moves
$moves = Activemove::model()->findAll();
foreach ($moves as $move) {
// Move rig
$result = [b]omegaRig::moveRigXY($move->rigid, $move->x, $move->y, $move->speed);[/b]
// If Rig at final stop start extract/salvage if applicable
if ($result == 'arrived') {
if (! is_null($move->resourcenodeid)) {
// start an extraction
omegaExtract::startExtraction($move->rigid,$move->resourcenodeid);
} elseif (! is_null($move->salvageid)) {
// start salvage operation
}
Activemove::model()->deleteByPk($move->id);
}
}
}
public function moveRigXY($rigid, $x, $y, $speed, $duration = 1) {
// speed in km/hr, duration in ticks
if (is_int($rigid)) {
echo "ping\n";
$rig = Rig::model()->findByPk($rigid);
} else {
echo "pong\n";
$rig = $rigid;
}
This always returns "pong" as it is not recognizing $rigid as a 1 (one).