Yii Framework Forum: Fatal Error: Call To A Member Function Isattributerequired() On A Non-Object - Yii Framework Forum

Jump to content

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

Fatal Error: Call To A Member Function Isattributerequired() On A Non-Object Rate Topic: -----

#1 User is offline   Junior josehp 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 21-January 14

Posted 28 January 2014 - 06:32 PM

hi,

my error occurs when you create the update function of a form with two modules, the error is as follows:
Fatal error: Call to a member function isAttributeRequired () on a non-object in C: \ xampp \ htdocs \ yii \ framework \ web \ helpers \ CHtml.php on line 1414

My Control Persona


public function actionCreate()
	{
		$model=new Persona;
		$model_empleado=new Empleado;

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

		if(!empty($_POST))
			{
				// Set attribute 
				$model->attributes=$_POST['Persona'];  
				// Set attribute 
				$model_empleado->attributes=$_POST['Empleado'];
				
				// Validate all three model
				$valid=$model->validate();
				$valid=$model_empleado->validate() && $valid;
 
		 
				if($valid)
					{ 
						$model->save();
						$idpersona = $model->PersonaId;
			 
						// Set saved address as user home id
						$model_empleado->EmpleadoPersonaId = $idpersona;
						$model_empleado->save();
						$this->redirect(array('view','id'=>$model->PersonaId));
					}
			}	

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

	/**
	 * Updates a particular model.
	 * If update is successful, the browser will be redirected to the 'view' page.
	 * @param integer $id the ID of the model to be updated
	 */
	public function actionUpdate($id)
	{
		$model=$this->loadModel($id);
		$model_empleado=Empleado::model()->findByPk($model->PersonaId);  


		if(!empty($_POST))
	    {
	        // Set attribute for home address
	        $model_empleado->attributes=$_POST['Empleado'];
	        // Set attribute for user data
	        $model->attributes=$_POST['Persona'];
	 
	        // Validate all three model
	        $valid=$model->validate();
			$valid=$model_empleado->validate() && $valid;
	 
	        if($valid)
	        {       
	            $model_empleado->save();
	            $model->save();
				$this->redirect(array('view','id'=>$model->PersonaId));
	        }
	    }
		
	    $this->render('update',array(
	        'model'=>$model,
	        'model_empleado'=>$model_empleado,
	    ));
	}

	protected function getGrupoOptions(){
		$gruposArray = CHtml::listData(Grupo::model()->findAll(),'GrupoId','GrupoDescripcion');
		return $gruposArray;
	}
	
	protected function getCargoOptions(){
		$cargosArray = CHtml::listData(Cargo::model()->findAll(),'CargoId','CargoDescripcion');
		return $cargosArray;
	}
	
	protected function getObraOptions(){
		$obrasArray = CHtml::listData(Obra::model()->findAll(),'ObraId','ObraDescripcion');
		return $obrasArray;
	}
	
	protected function getJornadaOptions(){
		$jornadasArray = CHtml::listData(Jornada::model()->findAll(),'JornadaId','JornadaDescripcion');
		return $jornadasArray;
	}


mi form is person


<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'persona-form',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'PersonaNombres'); ?>
		<?php echo $form->textField($model,'PersonaNombres',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'PersonaNombres'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'PersonaApellidos'); ?>
		<?php echo $form->textField($model,'PersonaApellidos',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'PersonaApellidos'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'PersonaFechaNacimiento'); ?>
		<?php echo $form->textField($model,'PersonaFechaNacimiento'); ?>
		<?php echo $form->error($model,'PersonaFechaNacimiento'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'PersonaSexo'); ?>
		<?php echo $form->dropDownList($model, 'PersonaSexo', array(1=>'Masculino', 0=>'Femenino'));?>
		<?php echo $form->error($model,'PersonaSexo'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'PersonaEstado'); ?>
		<?php echo $form->textField($model,'PersonaEstado'); ?>
		<?php echo $form->error($model,'PersonaEstado'); ?>
	</div>

<!--Modulo Empleado-->

	<div class="row">
		<?php echo $form->labelEx($model_empleado,'EmpleadoCodigo'); ?>
		<?php echo $form->textField($model_empleado,'EmpleadoCodigo'); ?>
		<?php echo $form->error($model_empleado,'EmpleadoCodigo'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model_empleado,'EmpleadoGrupoId'); ?>
		<?php echo $form->dropDownList($model_empleado,'EmpleadoGrupoId',$this->getGrupoOptions()); ?>
		<?php echo $form->error($model_empleado,'EmpleadoGrupoId'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model_empleado,'EmpleadoCargoId'); ?>
		<?php echo $form->dropDownList($model_empleado,'EmpleadoCargoId',$this->getCargoOptions()); ?>
		<?php echo $form->error($model_empleado,'EmpleadoCargoId'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model_empleado,'EmpleadoObraId'); ?>
		<?php echo $form->dropDownList($model_empleado,'EmpleadoObraId',$this->getObraOptions()); ?>
		<?php echo $form->error($model_empleado,'EmpleadoObraId'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model_empleado,'EmpleadoBonoSeguridad'); ?>
		<?php echo $form->dropDownList($model_empleado, 'EmpleadoBonoSeguridad', array(1=>'Si', 2=>'No'));?>
		<?php echo $form->error($model_empleado,'EmpleadoBonoSeguridad'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model_empleado,'EmpleadoSalario'); ?>
		<?php echo $form->textField($model_empleado,'EmpleadoSalario'); ?>
		<?php echo $form->error($model_empleado,'EmpleadoSalario'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model_empleado,'EmpleadoAsigFamiliar'); ?>
		<?php echo $form->dropDownList($model_empleado, 'EmpleadoAsigFamiliar', array(1=>'Si', 0=>'No'));?>
		<?php echo $form->error($model_empleado,'EmpleadoAsigFamiliar'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model_empleado,'EmpleadoJornadaId'); ?>
		<?php echo $form->dropDownList($model_empleado,'EmpleadoJornadaId',$this->getJornadaOptions()); ?>
		<?php echo $form->error($model_empleado,'EmpleadoJornadaId'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model_empleado,'EmpleadoEstado'); ?>
		<?php echo $form->textField($model_empleado,'EmpleadoEstado'); ?>
		<?php echo $form->error($model_empleado,'EmpleadoEstado'); ?>
	</div>
	
<!--End Modulo Empleado-->
	
	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->


my view Create
<?php
/* @var $this PersonaController */
/* @var $model Persona */

$this->breadcrumbs=array(
	'Personas'=>array('index'),
	'Create',
);

$this->menu=array(
	array('label'=>'List Persona', 'url'=>array('index')),
	array('label'=>'Manage Persona', 'url'=>array('admin')),
);
?>

<h1>Create Persona</h1>

<?php $this->renderPartial('_form', array('model'=>$model,'model_empleado'=>$model_empleado)); ?>


my view update
<?php
/* @var $this PersonaController */
/* @var $model Persona */

$this->breadcrumbs=array(
	'Personas'=>array('index'),
	$model->PersonaId=>array('view','id'=>$model->PersonaId),
	'Update',
);

$this->menu=array(
	array('label'=>'List Persona', 'url'=>array('index')),
	array('label'=>'Create Persona', 'url'=>array('create')),
	array('label'=>'View Persona', 'url'=>array('view', 'id'=>$model->PersonaId)),
	array('label'=>'Manage Persona', 'url'=>array('admin')),
);
?>

<h1>Update Persona <?php echo $model->PersonaId; ?></h1>

<?php $this->renderPartial('_form', array('model'=>$model,'model_empleado'=>$model_empleado)); ?>


please help for me, i need urgent solution mi problem, i'm hispano and my english is very basic.

add my captura for you helpme
Attached File  img.png (169.74K)
Number of downloads: 6
0

#2 User is offline   Argent 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 23-February 13
  • Location:Hungary

Posted 28 January 2014 - 09:40 PM

Hi, I think here:
$model_empleado=Empleado::model()->findByPk($model->PersonaId); 

the $model_empleado is will be NULL. Check the $model->PersonaId variable:
var_dump($model->PersonaId);

and thereafter check your empleado table that the questionable row is exists.
0

#3 User is offline   Junior josehp 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 21-January 14

Posted 29 January 2014 - 08:41 AM

i'm noob in Yii framework, how implement a function VAR_DUMP in view o controler o model, sorry my question is very basic.
0

#4 User is offline   Ahamed Rifaideen 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 381
  • Joined: 14-February 13
  • Location:chennai, tamilnadu

Posted 30 January 2014 - 11:11 AM

View PostJunior josehp, on 29 January 2014 - 08:41 AM, said:

i'm noob in Yii framework, how implement a function VAR_DUMP in view o controler o model, sorry my question is very basic.

you can call the yii dump helper as CVarDumper::dump($someData); like this in view, model, controller or anywhere
My Blog - Yii Learner
0

#5 User is offline   Junior josehp 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 21-January 14

Posted 30 January 2014 - 03:01 PM

thanks for your help, solve my problem because the load on the update form when I call, he called for findpk and compared directly with the id of the table Persona.

just change this line in model Persona

my error:
$model_empleado=Empleado::model()->findByPk($model->PersonaId);  

my solve
$model_empleado=Empleado::model()->find('EmpleadoPersonaId=?',array($model->PersonaId));


thanks!
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