Form Model Value

ok ok, sorry, now here is my problem:

i am doing an ask-answer system. i use a clistview to present the ask-list, the view.php like:




$this->renderPartial('_form', array(

	'model' => $model,

	'buttons' => 'create'));

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

	'dataProvider'=>$dataProvider,

	'itemView'=>'_view',

	'summaryText'=>'',

	'id'=>'ask-list',

));



the AskController.php is




public function actionIndex() {

	$model = new Ask;	

	$criteria = new CDbCriteria(array('order'=>'create_at DESC',));

	$dataProvider = new CActiveDataProvider('Ask', array(

		'pagination'=>array('pageSize'=>10),'criteria'=>$criteria,));

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

		'model' => $model,

		'dataProvider' => $dataProvider,

	));

}



the _view.php is




<div class="content-metadata">

	<?php echo GxHtml::encode($data->description); ?>

</div>

<div class="answer-create-form" id="answer-create-form_<?php echo $data->id;?>">

<?php $answer = new Answer;

$answer->ask_id=$data->id;//in this way, the controller cannot get $answer's ask_id

$form = $this->beginWidget('GxActiveForm', array(

	'id' => 'answer-form',

	'action' => $this->createUrl('/answer/create'),

	'enableAjaxValidation' => false,

));

echo $form->textArea($answer, 'description');

//echo $form->dropDownList($answer, 'ask_id', GxHtml::listDataEx(Ask::model()->findAllAttributes(null, true)));

//in this way, the controller can get $answer's ask_id, but i dont want use this way, because this ask_id should be set automatically, rather than via dropdownlist.


echo GxHtml::submitButton(Yii::t('app', 'Save'));

$this->endWidget();

?>

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

<div class="comment-list" id="answer_list_<?php echo $data->id;?>">

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

		'id' => 'answer-list_'.$data->id,

		'dataProvider'=>new CArrayDataProvider($data->answers, array(

			'keyField'=>'id',

			'pagination' => array(

				'pageSize' => 5,

			),

		)),

		'itemView' => '/answer/_view',

	));?>

</div>



as you can see, in every ask-item contains a answer-create-form and a answer-list, what i want to do now is to make the answer-create-form works.

this is the AnswerController:




public function actionCreate() {

	$model = new Answer;

	if (isset($_POST['Answer'])) {

		$model->setAttributes($_POST['Answer']);

		if ($model->save()) {

			if (Yii::app()->getRequest()->getIsAjaxRequest())

				Yii::app()->end();

			else

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

		}

	}


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

}



did i make myself clear?

please help me!

What are you trying to do exactly? Also what’s the controller code where you call that view?

you cant just dump in some code and ask why the above works and other shit does not work, you did not even mention what error you get

did i make myself clear?

please help me!

what happens when you try to save the model do you get any error or anything do you have any validation rules

no js errors;

in _view.php, I create a $answer, and set $answer->ask_id=$data->id, but in controller, I cannot get the value of $answer->ask_id. Its null.