Yii Framework Forum: Saving Data to the models - Yii Framework Forum

Jump to content

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

Saving Data to the models Rate Topic: -----

#1 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 589
  • Joined: 26-November 10
  • Location:Sialkot, Pakistan

Posted 23 December 2010 - 04:12 AM

Hi dears,

I have the tables with fields as

Section
Section_id
Categorie
category_id

The relation of both of the tables is stored in another table
section_category_relation as
section_id,category_id

I want to save the section_id and category_id in the section_category_relation while creating the new category.

How to do that

I have the following code segment for it

in categorycontroller.php
  createAction(){
          $category=new Categories; // category model
          $section= new Sections ;//
}



How to save the section_id,category_id in the section_category_relation table?

Thanks
Cheers
PeRoChAk
Cheap Domain & Hosting - Web & App Design - Web Application Development

My Page
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,558
  • Joined: 12-October 09
  • Location:Croatia

Posted 23 December 2010 - 04:20 AM

Create a model for the relation table... and you know all the rest :)

$relation= new RelationModel;   	// model of your relation (like section_category)
$relation.section_id=$section.id;
$relation.category_id=$category.id;
$relation->save();

Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 589
  • Joined: 26-November 10
  • Location:Sialkot, Pakistan

Posted 23 December 2010 - 04:51 AM

View Postmdomba, on 23 December 2010 - 04:20 AM, said:

Create a model for the relation table... and you know all the rest :)

$relation= new RelationModel;   	// model of your relation (like section_category)
$relation.section_id=$section.id;
$relation.category_id=$category.id;
$relation->save();



Thanks dear, It works but with bit of modification

$relation= new RelationModel;   	// model of your relation (like section_category)
$relation['section_id']=$section.id;
$relation['category_id']=$category.id;
$relation->save();

Cheers
PeRoChAk
Cheap Domain & Hosting - Web & App Design - Web Application Development

My Page
0

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,558
  • Joined: 12-October 09
  • Location:Croatia

Posted 23 December 2010 - 04:53 AM

I was typing too fast :), but as it's an object you can use it as

$relation->section_id


at least for me it's more readable than the array notation...
Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 589
  • Joined: 26-November 10
  • Location:Sialkot, Pakistan

Posted 23 December 2010 - 05:12 AM

You are right.

Thanks
Cheers
PeRoChAk
Cheap Domain & Hosting - Web & App Design - Web Application Development

My Page
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