Yii Framework Forum: Massive Assignment - Yii Framework Forum

Jump to content

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

Massive Assignment i need to do massive assignment Rate Topic: -----

#1 User is offline   developer! 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 28-November 12

Posted 31 December 2012 - 07:01 AM

Hi Experts,

I'm able to assign single field each time. but I need to do massive assignment, i'm facing problem with file upload field which needs to be stored in file model(other table). and i need to get the id for that file from file model, then i need to store this file_id in my someModel.this is working fine. but how can i do this with massive assignment in this scenario. when I tried to do this with the following code its not working.. getting validation error "fields with * are required"
but I didn't write any rule for this file field as this file will be stored in file model(other model). after storing this fileModel. i need to get the id for this file and i'll use this file_id for my someModel.


if (isset($_POST['someModel'])) {
			$model->attributes = $_POST['someModel'];
			

			$fileModel->file = CUploadedFile::getInstance($model, 'file');
			
		// If validation successful...

			if ($model->validate()) {

				// Save fileModel
				if ($fileModel->saveImage()) {

				        // Save the someModel after getting file_id from fileModel
					$model->file_id = $fileModel->id;
					$model->save();




this is my code which is working fine..for individual field assignments:

 if (isset($_POST['someModel'])) {
			//$model->attributes = $_POST['someModel'];
			$model->name = $_POST['someModel']['name'];
			$model->description = $_POST['someModel']['description'];
			$model->email = $_POST['someModel']['email'];
			$model->misc = $_POST['someModel']['misc'];
			$fileModel->file = CUploadedFile::getInstance($model, 'file');
	

			// If validation successful...

			if ($model->validate()) {

				// Save fileModel
				if ($fileModel->saveImage()) {
                                      // Save the someModel after getting file_id from fileModel
					$model->file_id = $fileModel->id;
					$model->save();
                                       }



can any one pls tell me how to do this




Thanks in advance
0

#2 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 08 January 2013 - 08:02 AM

multiple files at a time? i dnt get ur query!!

if u want multiple file field just use like file[], this will post as an array to the action.

try it

and u can save each file, if the model that saving file details is a different one , then use "lastinsertedid" to get the last inserted id .
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#3 User is offline   developer! 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 28-November 12

Posted 08 January 2013 - 08:33 AM

View PostRajith R, on 08 January 2013 - 08:02 AM, said:

multiple files at a time? i dnt get ur query!!

if u want multiple file field just use like file[], this will post as an array to the action.

try it

and u can save each file, if the model that saving file details is a different one , then use "lastinsertedid" to get the last inserted id .



thanks for your reply rajith..i solved it.
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