Yii Framework Forum: to add an image in a database and display the same - Yii Framework Forum

Jump to content

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

to add an image in a database and display the same

#1 User is offline   nigilan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 13-December 11

Posted 13 December 2011 - 02:48 PM

hi guys, i know this is a known issue but i cannot resolve it,

my table structure is

create table tbl_pic(id integer primary key, name text, password text, imgdata longblob);

My error is:

CException

Property "Pic." is not defined.


public function __set($name,$value)
139 {
140 if($this->setAttribute($name,$value)===false)
141 {
142 if(isset($this->getMetaData()->relations[$name]))
143 $this->_related[$name]=$value;
144 else
145 parent::__set($name,$value);
146 }
147 }
148



i hav attached the necessary files. Anyone pls save time to correct my issue. thanks in advance..

Attached File(s)


0

#2 User is offline   Pravin Gajera 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 137
  • Joined: 25-October 11
  • Location:India

Posted 18 December 2011 - 11:25 PM

Hi

May be table prefix problem.

tbl_pic than also it consider Pic.

can you try with table name only " pic "

Thanks
0

#3 User is offline   nigilan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 13-December 11

Posted 20 December 2011 - 12:29 AM

thanks for your reply.. but still i am getting the same error...



CException

Property "pic1." is not defined.

After changing as you said , i got the above error...
0

#4 User is offline   nigilan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 13-December 11

Posted 24 December 2011 - 08:00 AM

thanks I have solved the prob...

[ code ]
public function actionCreate()
{
$model=new Images;

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

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

//$model->image_name = CUploadedFile::getInstance($model,'image_name');
$myfile=CUploadedFile::getInstance($model,'image_name');
if (is_object($myfile) && get_class($myfile)==='CUploadedFile') {
$model->image_name=$myfile->name;
}

if($model->save()) {
//$model->imagenurl->saveAs('../images/'.$model->idProducto.'_'. $model->imagenurl);

if (is_object($myfile))
$myfile->saveAs(dirname(__FILE__).'/../../images/'.$model->image_name);
$this->redirect(array('view','id'=>$model->image_id));
}
}

$this->render('create',array(
'model'=>$model,
));
}


[ /code ]
That above one is workinf...

This post has been edited by nigilan: 25 December 2011 - 11:45 AM

0

#5 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 24 December 2011 - 09:37 AM

Please, use [ code ][ /code ] tags when posting a code (<> button).
0

#6 User is offline   nigilan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 13-December 11

Posted 24 December 2011 - 02:22 PM

sure I will ... after this
0

#7 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 24 December 2011 - 02:52 PM

View Postnigilan, on 24 December 2011 - 02:22 PM, said:

sure I will ... after this

If you have time, then edit your posts with "Edit" button under them :)
0

#8 User is offline   tpandi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 22-May 12

Posted 23 May 2012 - 12:18 AM

Hi i am Pandi This code which path(.php) to use



public function actionCreate()
{
$model=new Images;

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

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

//$model->image_name = CUploadedFile::getInstance($model,'image_name');
$myfile=CUploadedFile::getInstance($model,'image_name');
if (is_object($myfile) && get_class($myfile)==='CUploadedFile') {
$model->image_name=$myfile->name;
}

if($model->save()) {
//$model->imagenurl->saveAs('../images/'.$model->idProducto.'_'. $model->imagenurl);

if (is_object($myfile))
$myfile->saveAs(dirname(__FILE__).'/../../images/'.$model->image_name);
$this->redirect(array('view','id'=>$model->image_id));
}
}

$this->render('create',array(
'model'=>$model,
));
}
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