Register here!

Forgot password?

ASK NEW QUESTION

Home Page » Active Record » How to send file from model to another model..?
0 Votes
Vote Con!

How to send file from model to another model..?

databasefilemodelsend

hi.
I have two modules. Content && media.
I want to take file from content/category/create and send to media/photo/create.
I do:

  1.     public function actionCreate()
  2.     {
  3.         $model=new Category;
  4.         $this->performAjaxValidation($model);
  5.  
  6.         if(isset($_POST['Category']))
  7.         {
  8.             $model->attributes=$_POST['Category'];
  9.  
  10.             $file = CUploadedFile::getInstance($model, 'default_image');
  11.  
  12.             if(!is_null($file))
  13.             {
  14.                 $image = new Photo;
  15.                
  16.                 $image->fileimg = $file;
  17.                 $image->filename = $file->getName();
  18.                 $image->name = $file->getName();
  19.                 $image->extension = $file->getExtensionName();
  20.                 $image->byte_size = $file->getSize();
  21.                 $image->mime_type = $file->getType();
  22.  
  23.                 if($image->save(true))
  24.                 {
  25.                     $model->default_image = $image->getPrimaryKey();
  26.                 }
  27.                 else
  28.                     throw new CHttpException(400, 'file not saved');
  29.             }
	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

 

Answers (1)

  1. 0 votes

    What do you send to media/photo/create? the file itself or the name? if its just the name use

    1. $this->redirect('media/photo/create', array('file'=>'myfile');
    $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

© YiiAnswers.com 2011. All rights reserved.

Switch to our mobile site