Hello All,
I am newbie to the beautifull Yii Framework.I was going through the wiki docs of Yii.I got a link Wiki link where I got something that I was needed.So I made all the process like the tutorial.But still I can’t achive any success.
My database was like this
==== Job ====
id
job_name
job_description
created_at
updated_at
==== Person ====
id
job_id
person_name
description
created_at
updated_at
My _form.php for Person was like this
<?php echo $form->errorSummary($model); ?>
<div class="row">
<div id="job">
<?php echo $form->dropDownList($model,'job_id',CHtml::listData(Job::model()->findAll(),'job_id','description'),array('prompt'=>'Select')); ?>
<?php echo CHtml::ajaxLink(Yii::t('job','Create Job'),$this->createUrl('job/addnew'),array(
'onclick'=>'$("#jobDialog").dialog("open"); return false;',
'update'=>'#jobDialog'
),array('id'=>'showJobDialog'));?>
<div id="jobDialog"></div>
</div>
</div>
And the actionAddnew() in job controller is like this
public function actionAddnew()
{
$model=new Job;
// Ajax Validation enabled
$this->performAjaxValidation($model);
// Flag to know if we will render the form or try to add
// new jon.
$flag=true;
if(isset($_POST['Job']))
{
$flag=false;
$model->attributes=$_POST['Job'];
if($model->save())
{
//Return an <option> and select it
echo CHtml::tag('option',array ('value'=>$model->jid,'selected'=>true),CHtml::encode($model->jdescr),true);
}
}
if($flag)
{
Yii::app()->clientScript->scriptMap['jquery.js'] = false;
$this->renderPartial('createDialog',array('model'=>$model,),false,true);
}
}
As per the tutorial I have made another two files called as createDialog.php and _formDialog.php in job view folder.
The code for createDialog.php is like this
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'jobDialog',
'options'=>array(
'title'=>Yii::t('job','Create Job'),
'autoOpen'=>true,
'modal'=>'true',
'width'=>'auto',
'height'=>'auto',
),
));
echo $this->renderPartial('_formDialog', array('model'=>$model)); ?>
<?php $this->endWidget('zii.widgets.jui.CJuiDialog');?>
The code for _formDialog.php is like this
<div class="form" id="jobDialogForm">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'job-form',
'enableAjaxValidation'=>true,
));
//I have enableAjaxValidation set to true so i can validate on the fly the
?>
<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,'jid'); ?>
<?php echo $form->textField($model,'jid',array('size'=>60,'maxlength'=>90)); ?>
<?php echo $form->error($model,'jid'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'jdescr'); ?>
<?php echo $form->textField($model,'jdescr',array('size'=>60,'maxlength'=>180)); ?>
<?php echo $form->error($model,'jdescr'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::ajaxSubmitButton(Yii::t('job','Create Job'),CHtml::normalizeUrl(array('job/addnew','render'=>false)),array('success'=>'js: function(data) {
$("#Person_jid").append(data);
$("#jobDialog").dialog("close");
}'),array('id'=>'closeJobDialog')); ?>
</div>
<?php $this->endWidget(); ?>
</div>
But still I am not getting any success.So where I am wrong in this?Any help and suggestions will be highly appreciable.