how to new a model instance in another controller

hi, i am new to Yii, i tried to new A Model_a instance in Controller_B like this:

$a = new Model_a;

or

$a = Model_a::model->init();

both are not working for me.

anybody know how to do this, thanks!

What is "not working"… The object is not created? There is an error shown in the screen? What is the error?

BTW: Your first approach is the correct one…

try to

$a = new Model_a;

$a->save();

hi, all

i have this action in Controller_photos :





$model=new Photos;

$photocate = new Photocate; 

$photocate->title=$event->title; 

$photocate->save();

$model->photocate_id=$imagename;

$model->createTime=time();

			       

$model->save()



no errors after running.

i checked the database, i can1 recorder in table_photos, nothing is in table_photocate.

really strange, Yii just igore some code:




$photocate = new Photocate; 

$photocate->title=$event->title; 

$photocate->save();



what does this display

echo $event->title;

die;

are you assigning $photocate->title to null?

that’s what your code example looks like, but I assume there is more to it.

doodle