无法在Yii的字段中填充相关模型的值,但可以在屏幕上打印

时间:2013-09-02 08:27:55

标签: php yii

我是Yii框架的新手。 _form.php 包含两个表的字段。我可以获取其字段中填充的一个表的值。但是,对于第二个模型,值不会在 update.php 的相应字段中填充。但是,我可以在屏幕上打印它。为什么会这样呢?如何将其填充到表单中的字段。

控制器:

public function actionUpdate($id) {
    $model_al = new AuditLogin;
    $model = ApartmentSettings::model()->findByPk($id);
    $model_apt = Apartment::model()->findByAttributes(array(
                     'Id' => $model->ApartmentId
                 ));

    if(isset($_POST['ApartmentSettings']) && isset($_POST['AuditLogin'])) {

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

        if($model->save())
            $model_al->attributes = $_POST['AuditLogin'];

        $approval = Yii::app()->getRequest()->getParam('approval');

        if($approval == 0) {
            $model_al->moduleId = "1001";
            $model_al->content = $model->GreetingsApprovedSMSText;
            $greet_approve = $model->GreetingsApproval;

            if($greet_approve == 0)
                $model_al->activity = "Greetings approval rejected";
            else
                $model_al->activity = "Greetings approval accepted";
            echo $approval;
        }
        elseif($approval == 1) {
            $model_al->moduleId = "1002";
            $model_al->content = $model->ContactApprovedSMSText;
            $contact_approve = $model->ContactApproval;

            if($contact_approve == 0)
                $model_al->activity = "Contact approval rejected";
            else
                $model_al->activity = "Contact approval accepted";
        }
        elseif($approval == 2) {
            if(isset($_POST['Apartment']))
                $model_apt->attributes = $_POST['Apartment'];

            $model_al->moduleId = "1004";
            $model_al->activity = "Microsite fields updated";
            $model_al->content = $_POST['Apartment']['MetatagsDesc'];
            $model_apt->save();
        }

        if($model_al->save())
            $this->redirect(array('admin', 'id' => $model->Id));
    }

    $this->render('update', array(
        'model' => $model,
        'model_apt' => $model_apt,
        'model_al' => $model_al,
    ));
}

当我在 update.php 中打印值时,值会在更新页面中打印。

<?php
echo "latitude :" . $model_apt->Latitude;
echo "longitude :" . $model_apt->Longitude;
echo $this->renderPartial('_form', array(
    'model' => $model,
    'model_apt' => $model_apt,
    'model_al' => $model_al
));
?> 

但是,它不会填充在 _form.php 的字段中。

<div class="row">
    <?php echo $form->labelEx($model_apt, 'Latitude'); ?>            
    <?php echo $form->textField($model_apt, 'Latitude', 
        array('size' => 60, 'maxlength' => 250)); ?>
    <?php echo $form->error($model_apt, 'Latitude'); ?>    
</div>

<div class="row">        
    <?php echo $form->labelEx($model_apt, 'Longitude'); ?>            
    <?php echo $form->textField($model_apt, 'Longitude', 
        array('size' => 60, 'maxlength' => 250)); ?>
    <?php echo $form->error($model_apt, 'Longitude'); ?>
</div>

enter image description here

0 个答案:

没有答案