Yii Framework Forum: how to new a model instance in another controller - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

how to new a model instance in another controller Rate Topic: -----

#1 User is offline   kevin2010 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 17-January 10

Posted 05 March 2010 - 06:22 AM

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!
0

#2 User is offline   PoL 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 506
  • Joined: 05-November 08
  • Location:Buenos Aires, Argentina

Posted 05 March 2010 - 07:19 AM

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...
Don't say what you think, think what you say
The problem is communication! Excess of communication!
0

#3 User is offline   phpdevmd 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 16-April 09

Posted 05 March 2010 - 10:43 AM

try to

$a = new Model_a;
$a->save();
0

#4 User is offline   kevin2010 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 17-January 10

Posted 05 March 2010 - 08:08 PM

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();

0

#5 User is offline   got 2 doodle 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 247
  • Joined: 12-December 08
  • Location:Beautiful Nova Scotia, Canada

Posted 07 March 2010 - 04:06 PM

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
Check out myYii powered website
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users