Yii Framework Forum: [Solved] Fatal Error: Call To A Member Function Saveas() On A Non-Object In Bla...bla...bla... - Yii Framework Forum

Jump to content

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

[Solved] Fatal Error: Call To A Member Function Saveas() On A Non-Object In Bla...bla...bla... Rate Topic: -----

#1 User is offline   dst34m 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 07-November 12

Posted 18 January 2014 - 11:53 AM

master mohon bantuannya ya,,
ane kemarin bikin upload file gambar, nah waktu ane save form muncul kyk gini kalau fileFieldRow nya ndak di isi,
Fatal error: Call to a member function saveAs() on a non-object in C:\xampp\htdocs\att\protected\controllers\EMPLOYEEController.php on line 76

tp datanya tetep ksimpen, ini kira-kira kenapa ya??

ini koding action create dan action update ane:

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

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

		if(isset($_POST['EMPLOYEE']))
		{
			$model->attributes=$_POST['EMPLOYEE'];
			$simpanGambar=CUploadedFile::getInstance($model,'EMP_PHOTO');
			
			if($model->save())
			{
				$simpanGambar->saveAs(Yii::app()->basePath.'/../photo/'.$model->EMP_ID.'.png');
				
				Yii::app()->user->setFlash('success', '<strong>Well done!</strong> Data karyawan baru berhasil disimpan.');
				$this->redirect(array('view','id'=>$model->EMP_ID));
			}
		}

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



actionUpdate()
public function actionUpdate($id)
	{
		$model=$this->loadModel($id);

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

		if(isset($_POST['EMPLOYEE']))
		{
			$_POST['EMPLOYEE']['EMP_PHOTO'] = $model->EMP_PHOTO;
			$model->attributes=$_POST['EMPLOYEE'];
			
			$simpanGambar=CUploadedFile::getInstance($model,'EMP_PHOTO');
			
			if($model->save())
			{
				if(!empty($simpanGambar))
				{
					$simpanGambar->saveAs(Yii::app()->basePath.'/../photo/'.$model->EMP_ID.'.png');
				}
				
				Yii::app()->user->setFlash('success', '<strong>Well done!</strong> Data karyawan berhasil diperbaharui dan disimpan.');
				$this->redirect(array('view','id'=>$model->EMP_ID));		
			}
		}

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


ane udah cb search ada sih, tp masih belum paham, maybe ada yang bisa bantu ngjelasin dengan kalimat yang mudah dimengerti :D
thank's...
0

#2 User is offline   dst34m 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 07-November 12

Posted 20 January 2014 - 05:51 AM

udah cari-cari di mbah google, katanya sih di tambahin ini :

<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
	'id'=>'employee-form',
	'enableAjaxValidation'=>false,
	'htmlOptions' => array('enctype' => 'multipart/form-data'), //<---- di tambahin baris ini
)); ?>



tp udah ane cb kok masih tetep aja ya keluar
Fatal error: Call to a member function saveAs() on a non-object in C:\xampp\htdocs\att\protected\controllers\EMPLOYEEController.php on line 76


line 76 itu di controller ane buat upload gambar gan ;
$simpanGambar->saveAs(Yii::app()->basePath.'/../photo/'.$model->EMP_ID.'.png');



apa ya yang masih kurang.. :(
0

#3 User is offline   rei 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 335
  • Joined: 10-November 10

Posted 20 January 2014 - 09:06 PM

View Postdst34m, on 18 January 2014 - 11:53 AM, said:

ane kemarin bikin upload file gambar, nah waktu ane save form muncul kyk gini kalau fileFieldRow nya ndak di isi,

Fatal error: Call to a member function saveAs() on a non-object in C:\xampp\htdocs\att\protected\controllers\EMPLOYEEController.php on line 76



Ane sendiri belum cek tapi setau ane kalo field filenya gak diisi, variabel $simpanGambar tidak terisi sebagaimana seharusnya. Apa sudah coba untuk melakukan pengecekan tambahan?

if (isset($simpanGambar))
   $simpanGambar->saveAs(Yii::app()->basePath.'/../photo/'.$model->EMP_ID.'.png');



View Postdst34m, on 18 January 2014 - 11:53 AM, said:

tp datanya tetep ksimpen, ini kira-kira kenapa ya??


Mungkin karena $model->save() sudah dieksekusi, sedangkan line yang error ada di baris berikutnya:

$simpanGambar->saveAs(Yii::app()->basePath.'/../photo/'.$model->EMP_ID.'.png');

Fipick - Find and pick recommendations
0

#4 User is offline   dst34m 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 07-November 12

Posted 20 January 2014 - 09:31 PM

wah iya gan, ternyata kurang untuk pengecekan diisi atau tidak nya :D

if (isset($simpanGambar))
   $simpanGambar->saveAs(Yii::app()->basePath.'/../photo/'.$model->EMP_ID.'.png');



thank's ya gan...
0

#5 User is offline   nashrul 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 11-June 13

Posted 18 March 2014 - 01:03 AM

View Postdst34m, on 20 January 2014 - 09:31 PM, said:

wah iya gan, ternyata kurang untuk pengecekan diisi atau tidak nya :D

if (isset($simpanGambar))
   $simpanGambar->saveAs(Yii::app()->basePath.'/../photo/'.$model->EMP_ID.'.png');



thank's ya gan...


Gan, ane msih bingung, hehe...
Tolong upload script, form, ama controller-nya yg udah berhasil.
Mkasih...

--SOLVED-- :D
0

#6 User is offline   dickypadang 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 31-March 12

Posted 21 May 2014 - 03:54 AM

View Postnashrul, on 18 March 2014 - 01:03 AM, said:

Gan, ane msih bingung, hehe...
Tolong upload script, form, ama controller-nya yg udah berhasil.
Mkasih...

--SOLVED-- :D

dibelakangnnya dikasih true gan. Berikut ane upload script projectnya. Untuk tabel database bisa dicopy paste script ini

CREATE TABLE IF NOT EXISTS `dokumen` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nama` varchar(100) NOT NULL,
`tgl` date NOT NULL,
`deskripsi` varchar(250) NOT NULL,
`status` int(11) NOT NULL DEFAULT '0',
`keterangan1` varchar(250) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Table structure for table `dokumen_detail`
--

CREATE TABLE IF NOT EXISTS `dokumen_detail` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_dokumen` int(11) NOT NULL,
`nama_dok` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Attached File(s)


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