[SOLVED]id not being saved

hi, I have set the current logged in users id , plus the hidden field, but then when I save the company details, it’s not being saved in the table, it was “null” why is that?

here’s my the index view code from where the log in user can click the create company link as you can see, the mid is set as Yii:app()->user-id




<?php

$this->breadcrumbs=array(

	'Company Details',

);


$this->menu=array(

	array('label'=>'Create Company Details', 'url'=>array('create','mid'=>Yii::app()->user->id)),

);

?>


<h1>Company Details</h1>


<?php $this->widget('zii.widgets.CListView', array(

	'dataProvider'=>$dataProvider,

	'itemView'=>'_view',

)); ?>



at the _form file , i have this part of the code. I have the hiddenField set

as the MemberShipID , it’s the column in my companies table




<div class="form">


 

<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'wsmembersdetails-form',

	'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->hiddenField($model,'MemberShipID'); ?>

	</div>



here’s my actionCreate()




	public function actionCreate()

	{

		$model=new Wsmembersdetails;

		

		$model->MemberShipID = $this->_member->MemberShipID;


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['Wsmembersdetails']))

		{

			$model->attributes=$_POST['Wsmembersdetails'];

			if($model->save())

				$this->redirect(array('view','id'=>$model->CompanyID));

		}


		

		$this->render('create',array(

			'model'=>$model

		));

	}



I don’t know what’s wrong, did I miss something ?

Hidden field’s value won’t be assigned to a model until you define it as “safe attribute”. But be careful when you allow users to set such values (they can put anything into this field).

any other best thing to do aside from setting it as safe ?, i might get axed in the future if we run to any problems ( and also, I did tried setting it as safe, didn’t helped )

This attribute must be safe if you are going to set it somewhere outside a model. If it is a foreign key in your table, then you can use CExistValidator.

Try to see what happens to MemberShipID on different steps. Print it before the form, after validation etc.

problem solved, am sooo stupid, i forgot to uncomment the




	public function filters()

	{

		return array(

			'accessControl', // perform access control for CRUD operations

			'memberContext + create',

		);

	}



that’s why the MemberShipID is not being saved

anyway thanks for the tip… and also i noticed, this thread should be in 1.1.x section XD

thanks for the help anyway