Hello,
I am playing around with Yii for a few weeks and it is very helpful, but sometimes I strange things, or how you call it: esoteric things happen.
I started with the Blog Tutorial, so I decided to extend it for better understand how yii works.
My testarea runs under Windows XP / 7 and XAMPP with MySql (InnoDB)
The database has 4 Tables: Blog -> Tag -> Entry -> Comment (Always 1:n)
The generated relation in Blog and Tag work fine:
models/Blog - relations:
'tags' => array(self::HAS_MANY, 'Tag', 'blog_id'),
_view.php:
echo $data->tags[0]->tagtitle;
models/Tag - relations:
'entry' => array(self::HAS_MANY, 'Entry', 'tag_id'),
_view.php:
echo $data->entry[0]->entrytitle;
Now I have problems:
models/Entry - relation:
'comments' => array(self::HAS_MANY, 'Comment', 'entry_id'),
_view.php:
echo $data->comments[0]->commenttitle
Gives the Error:
PHP notice - Undefined offset: 0
41 echo $data->comments[0]->commenttitle;
I have absolutely no idea what the problem is. First I deleted the DB and re-created it.
Then I count the array: 1 (Yes there is data in the table).
The varDump shows me the Information, but I can’t get the data like you seen above!
array
(
0 => Comment#1
(
[CActiveRecord:_md] => CActiveRecordMetaData#2
(
...
...
[CActiveRecord:_attributes] => array
(
'id' => '1'
'commenttext' => 'This is a comment'
'commentdate' => '2012-12-11 14:09:08'
'spot_id' => '1'
)
...
I hope the Information is enough to help me and solve the problem. or do you need the whole varDump?
Thank you for your help!
Dianamo