Home Page » Active Record » How to send file from model to another model..?
0
Votes
How to send file from model to another model..?
hi.
I have two modules. Content && media.
I want to take file from content/category/create and send to media/photo/create.
I do:
- public function actionCreate()
- {
- $model=new Category;
- $this->performAjaxValidation($model);
- if(isset($_POST['Category']))
- {
- $model->attributes=$_POST['Category'];
- $file = CUploadedFile::getInstance($model, 'default_image');
- if(!is_null($file))
- {
- $image = new Photo;
- $image->fileimg = $file;
- $image->filename = $file->getName();
- $image->name = $file->getName();
- $image->extension = $file->getExtensionName();
- $image->byte_size = $file->getSize();
- $image->mime_type = $file->getType();
- if($image->save(true))
- {
- $model->default_image = $image->getPrimaryKey();
- }
- else
- throw new CHttpException(400, 'file not saved');
- }
public function actionCreate()
{
$model=new Category;
$this->performAjaxValidation($model);
if(isset($_POST['Category']))
{
$model->attributes=$_POST['Category'];
$file = CUploadedFile::getInstance($model, 'default_image');
if(!is_null($file))
{
$image = new Photo;
$image->fileimg = $file;
$image->filename = $file->getName();
$image->name = $file->getName();
$image->extension = $file->getExtensionName();
$image->byte_size = $file->getSize();
$image->mime_type = $file->getType();
if($image->save(true))
{
$model->default_image = $image->getPrimaryKey();
}
else
throw new CHttpException(400, 'file not saved');
}…
By eibrahimov in Active Record · Asked 436 days 11 hours 58 mins ago
Questions: 4 Accepted: 0 ( 0% ) | Reputation: 0
Possibly related Questions
TAGS
actioncreate ( x 2 )ACTIVERECORD ( x 4 )AJAX ( x 10 )ajaxSubmitButton ( x 4 )AR ( x 2 )cactivedataprovider ( x 2 )CActiveForm ( x 2 )cactiverecord ( x 2 )CGridView ( x 14 )CJuiAutoComplete ( x 3 )CJuiDialog ( x 8 )CListView ( x 8 )controller ( x 7 )Css ( x 2 )CStarRating ( x 2 )CTreeView ( x 2 )database ( x 5 )dialog ( x 2 )dropdownlist ( x 3 )EGMaps ( x 3 )extension ( x 3 )file ( x 2 )form ( x 6 )Giix ( x 2 )gridview ( x 2 )html ( x 2 )javascript ( x 3 )many_many ( x 4 )merge ( x 2 )model ( x 4 )Modules ( x 3 )multilanguage ( x 2 )php ( x 2 )redirect ( x 4 )Registration ( x 3 )relations ( x 5 )renderPartial ( x 8 )session ( x 2 )sorting ( x 3 )sql ( x 4 )url ( x 3 )urlManager ( x 3 )validation ( x 3 )yii ( x 11 )YiiAnswers Site ( x 4 )This website counts Questions and 429 Answers by 16784 registered users.

What do you send to media/photo/create? the file itself or the name? if its just the name use
$this->redirect('media/photo/create', array('file'=>'myfile');If its not redirection and you wish to do data manipulation with the file, I recommend you that you handle what media/photo/create requires with it, then redirect for the rest of the processes.
By tonydspaniard · 436 days 5 hours 39 mins ago
Questions: 2 Accepted: 0 ( 0% ) | Reputation: 0