0

我把它放在我的视图上,我必须添加它<?php $model = new Usuarios; ?>并且它可以工作,但实际上并没有将信息发送到数据库。

我尝试了另一个视图(索引视图),没有这个它可以工作:<?php $model = new Usuarios; ?>.

<a class="list-group-item">
    <form role="form">
        <div class="form">
            <?php $model = new Usuarios; ?>
            <?php $form = $this->beginWidget('CActiveForm', array(
                'id' => 'usuarios-form',
                'action' => $this->createUrl("usuarios/create"),
                'enableAjaxValidation' => false,
            )); ?>

            <?php echo $form->errorSummary($model); ?>

            <div style="padding:1px;" class="input-group input-group-sm">
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-user" style="color:white"></span>
                </span>
                <?php echo $form->textField($model, 'Nombre', array('maxlength' => 128, 'placeholder' => 'Nombre y Apellido')); ?>
                <?php echo $form->error($model, 'Nombre'); ?>
            </div>

            <div class="row buttons" style="padding:4%; color:white ; font-size:1.5vmax; font-family: Signika; border-radius:30px">
                <center>
                    <?php echo CHtml::submitButton($model->isNewRecord ? 'Enviar' : 'Save'); ?>
                </center>
            </div>
            <?php $this->endWidget(); ?>   
        </div>
    </form>
</a>
4

1 回答 1

0

这是您的控制器操作应如下所示:

public function actionCreate() {
    $model = new Usuarios;

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

        // Populate the model with values from form
        // These attributes must be set to safe in the model rules() function
        $model->attributes = $_POST['Usuarios'];

        // ->save() will validate the model with the validation rules 
        // in the Usuarios.php model. If you do not want validation, use ->update()
        if($model->save()) {
            $this->redirect(array('view', 'id' => $model->primaryKey));
        }
    }

    $this->render('create', array(
        'model' => $model, // You pass the model to the view page
    ));
}

在您的模型中,您需要更新 rules() 函数以接受要保存在数据库中的字段:

public function rules() {
    return array(
        array('Nombre', 'safe'),
    );
}
于 2014-11-04T06:38:43.357 回答