A Strange Problem When Call A Model Static Function

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(





       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

Try below,

$channelModel =new Channel();

$data = $channelModel->getChannel();	

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

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?

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")

I see.

What do you do in Channel::getChannels()? Do you do something related to News model?

no,this function return a array for Channel::model()->findAll();

even the function do nothing, this problem still appear


Would you please show the minimum code that will reproduce the problem?

i try to move this problem to a new project but it’s not happen :unsure:

now i use lazy load "Channel" to avoid this problem

whatever, thank u for discussion~ :D

and i will figure out the reason for this situation


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~