F0ur
(Foureyesxu)
1
Hi all,
i happen to a strange problem.
i have a model channel
class Channel extends CActiveRecord
{
// ....
public static function getChannels()
{
// TO DO STH.
}
// ....
}
and have a model News
class News extends CActiveRecord
{
// ....
public function defaultScope()
{
return array(
'with' => array(
'channel',
)
);
}
public function relations()
{
return array(
'channel' => array(self::BELONGS_TO, 'Channel', 'channel_id'),
);
}
// ....
}
in crud, when i create a news, it’s fine.but i update a existed record, the “_form” can’t display when i use Channel::getChannels()
no error report, no debug report
when i comment defaultScope in Model News or Channel::getChannels(), it’s fine again.
so , how to fix it?
and Thank all first
kiran123
(Sharmakiran71)
2
Try below,
$channelModel =new Channel();
$data = $channelModel->getChannel();
F0ur
(Foureyesxu)
3
Thanks for reply
i think it can work but do not correct the underlying problem.
i hope figure out why this happen and how to avoid it
softark
(Softark)
4
Hi F0ur,
Could you show the code in "_form"?
How do you call Channel::getChannels()?
Hmm, did you say "Channel::getChannel()"? getChannel and getChannels are the different things. Which do you mean?
F0ur
(Foureyesxu)
5
it’s a write mistake when i posted,
i use the Channel::getChannels() (not use __get())
how do i call this function, even i var_dump(Channel::getChannels()) the problem happen to me.
in the controller, i call Channel::getChannels() before load News model, it works.
after load, it error.
so the problem lock to use "with" => array("channel")
softark
(Softark)
6
I see.
What do you do in Channel::getChannels()? Do you do something related to News model?
F0ur
(Foureyesxu)
7
no,this function return a array for Channel::model()->findAll();
even the function do nothing, this problem still appear
softark
(Softark)
8
OK.
Would you please show the minimum code that will reproduce the problem?
F0ur
(Foureyesxu)
9
i try to move this problem to a new project but it’s not happen 
now i use lazy load "Channel" to avoid this problem
whatever, thank u for discussion~ 
and i will figure out the reason for this situation
=============Edit=================
for this time i use ‘with’ => array(‘Channel’)…
this problem has gone out
really a strange situation, prehaps my IDE error i think…(such as sync code error)
thank u again~