public function actionCreate()
 {
     $model = new TtskTask();
     $model->scenario = $this->scenario;
     $this->performAjaxValidation($model, 'ttsk-task-form');
     if (isset($_POST['TtskTask'])) {
         $model->attributes = $_POST['TtskTask'];
         try {
             if ($model->save()) {
                 // add managers
                 if (isset($_POST['managers'])) {
                     foreach ($_POST['managers'] as $manager) {
                         $modelPerson = new TprsPersons();
                         $modelPerson->tprs_ttsk_id = $model->ttsk_id;
                         $modelPerson->tprs_pprs_id = $manager;
                         $modelPerson->save();
                     }
                 }
                 if (isset($_GET['returnUrl'])) {
                     $this->redirect($_GET['returnUrl']);
                 } else {
                     $this->redirect(array('view', 'ttsk_id' => $model->ttsk_id));
                 }
             }
         } catch (Exception $e) {
             $model->addError('ttsk_id', $e->getMessage());
         }
     } elseif (isset($_GET['TtskTask'])) {
         $model->attributes = $_GET['TtskTask'];
     }
     $this->render('create', array('model' => $model));
 }
<div class="table-header">
    <i class="icon-user"></i>        
    <?php 
    echo Yii::t('D2tasksModule.model', 'Tprs Persons');
    ?>
    <?php 
    if (Yii::app()->user->checkAccess("D2tasks.TprsPersons.Create")) {
        $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'ajaxButton', 'type' => 'primary', 'size' => 'mini', 'icon' => 'icon-plus', 'url' => array('//d2tasks/tprsPersons/ajaxCreate', 'field' => 'tprs_ttsk_id', 'value' => $modelMain->primaryKey, 'ajax' => 'tprs-persons-grid'), 'ajaxOptions' => array('success' => 'function(html) {$.fn.yiiGridView.update(\'tprs-persons-grid\');}'), 'htmlOptions' => array('title' => Yii::t('D2tasksModule.crud', 'Add new record'), 'data-toggle' => 'tooltip')));
    }
    ?>
</div>
 
<?php 
    if (empty($modelMain->tprsPersons)) {
        $model = new TprsPersons();
        $model->tprs_ttsk_id = $modelMain->primaryKey;
        $model->save();
        unset($model);
    }
    $model = new TprsPersons();
    $model->tprs_ttsk_id = $modelMain->primaryKey;
    // render grid view
    $can_edit_tprs = (bool) Yii::app()->user->checkAccess("D2tasks.TprsPersons.Update");
    $bft = !$can_edit_tprs ? 'false' : 'true';
    $this->widget('TbGridView', array('id' => 'tprs-persons-grid', 'dataProvider' => $model->search(), 'template' => '{summary}{items}', 'summaryText' => '&nbsp;', 'htmlOptions' => array('class' => 'rel-grid-view'), 'columns' => array(array('class' => 'editable.EditableColumn', 'name' => 'tprs_pprs_id', 'value' => '(!' . $bft . ' && !empty($data->tprs_pprs_id))?$data->tprsPprs->itemLabel:""', 'editable' => array('type' => 'select', 'url' => $this->createUrl('//d2tasks/tprsPersons/editableSaver'), 'source' => CHtml::listData(PprsPerson::model()->getSysCompanyPersons(), 'pprs_id', 'itemLabel'), 'apply' => $can_edit_tprs), 'htmlOptions' => array('class' => 'span6')), array('class' => 'editable.EditableColumn', 'name' => 'tprs_notes', 'editable' => array('type' => 'textarea', 'url' => $this->createUrl('//d2tasks/tprsPersons/editableSaver'), 'apply' => $can_edit_tprs), 'htmlOptions' => array('class' => 'span12')), array('class' => 'TbButtonColumn', 'buttons' => array('view' => array('visible' => 'FALSE'), 'update' => array('visible' => 'FALSE'), 'delete' => array('visible' => 'TRUE')), 'deleteButtonUrl' => 'Yii::app()->controller->createUrl("/d2tasks/tprsPersons/delete", array("tprs_id" => $data->tprs_id))', 'deleteConfirmation' => Yii::t('D2tasksModule.crud', 'Do you want to delete this item?'), 'deleteButtonOptions' => array('data-toggle' => 'tooltip'), 'htmlOptions' => array('class' => 'span1'), 'visible' => Yii::app()->user->checkAccess("D2person.TprsPersons.Delete")))));
    ?>

<?php 
    Yii::endProfile('tprs_ttsk_id.view.grid');
}
 public function loadModel($id)
 {
     $m = TprsPersons::model();
     // apply scope, if available
     $scopes = $m->scopes();
     if (isset($scopes[$this->scope])) {
         $m->{$this->scope}();
     }
     $model = $m->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('D2tasksModule.crud', 'The requested page does not exist.'));
     }
     return $model;
 }