In the below code can I save the ticket comment. Each ticket HasMany ticket comment. Following is the functionality to view a ticket along with all it’s ticket comments in the same screen. How do I allow posting of a new comment. How should I generate cHtml::textArea. Also would welcome any suggestions on any other other faults in my code(style,practices,pitfalls)
Controller:
$TicketComment = new TicketComment();
$this->render('view',array(
'model'=>$this->loadModel($id),
'ticketComments' => $TicketComment->findAllByTicket($id)
));
Model:
/**
* Retrieves a list of comments based on the ticket.
* @return CActiveDataProvider the data provider that can return the models.
*/
public function findAllByTicket($ticketID)
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
return new CActiveDataProvider($this, array(
'criteria'=>array(
'condition'=>'ticket_id='.intval($ticketID),
'with'=>array('User'),
),
));
}
View:
<h1>View Ticket #<?php echo $model->id; ?></h1>
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'id',
'title',
'TicketCategory.name',
'ticketstatus',
'tickettype',
'email',
'Assignee.username',
'created',
'modified',
),
)); ?>
<p> </p>
<h4>Ticket Comments</h4>
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$ticketComments,
'itemView'=>'..\ticketComments\_view',
)); ?>
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'ticket-form',
'enableAjaxValidation'=>false,
)); ?>
<div class="span12 well">
<form accept-charset="UTF-8" action="" method="POST">
<?php echo cHtml::textArea('TicketComment.description','TicketComment.description',array('class'=>'span12','rows'=>5)); ?>
<div class="pull-right">
<?php
$model->ticketstatus = ($model->ticketstatus != ('' or 'new' )) ? $model->ticketstatus : 'in_progress';
echo $form->dropDownList($model,'ticketstatus',ZHtml::enumItem( $model,'ticketstatus'), array('prompt'=>'in_progress'));
?>
</div>
<button class="btn btn-info" type="submit">Post Message</button>
</form>
</div>
<?php $this->endWidget(); ?>
i tried several things in place of TicketComment.description but all failed