Hello Gurus!
Hopefully you people can give me a hand in solving this problem. Maybe I am going YII blind at the moment which means that I am simply overlooking the obvious. If so you can flame me
My application is reading records from a database with two PK columns.
I have a controller where I have the following code:
$keyArray['Code'] = 1;
$keyArray['TimePeriod'] = 5;
$returnRecords = MyDbModel::model()->findAllByPk( $keyArray );
/*Now I loop over the array of ActiveRecords to print what's inside*/
$myFile = "C:\\aaa.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, "returnRecords: " . $returnRecords . "\n");
fwrite($fh, "count: " . count($returnRecords) . "\n");
foreach($returnRecords as $fieldList => $value){
fwrite($fh, "field: " . $fieldList . "\n");
fwrite($fh, "value: " . $value . "\n");
}
fclose($fh);
The output is as follows:
returnRecords: Array
count: 1
field: 0
I am using the print to file to see what’s inside the array. This is not what I expected. I do expect 1 row/record but why is field ‘0’?
When I use findByPK instead, i get nothing even though the 2 keys together are unique.
What am I doing wrong? I have never had problems reading records from the database before. This is the first table that has 2 primary keys, however. Might my problems have something to do with that?
Thank you in advance!