yii2中的ActiveForm名称

时间:2015-09-09 19:45:41

标签: activerecord yii2

我正在使用Yii2ActiveForm 正常情况下,如果ActiveForm中的任何输入已使用,则输入的名称应与ActiveRecord属性相同,该属性是数据库中相关表的列的名称。

出于某种原因,我想使用Active TextArea,它的名称也与Active Record属性不同。实际上我想得到TextArea's值并爆炸然后保存到数据库。< / p>

有没有办法使用ActiveReput,其名称与ActiveRecord属性不同?

查看:

<?php $form = ActiveForm::begin([
             'id'=>'import-student',
             'options'=>[
                 'class'=>'form-horizontal',
                 'enctype'=>'multipart/form-data']
             ]); ?>    

    <?= $form->field($model, 'first_name', ['inputOptions'=>[
                             'placeholder'=>'import Users as text']])
             ->textArea(['rows'=>'12','class'=>'form-control'])
             ->label(false); ?>  
    <?= Html::submitButton('Submint', ['class'=>'btn btn-primary']) ?> 

<?php ActiveForm::end(); ?>  

控制器:

public function actionImport()
{
    $model = new Student();

    if ($model->load(Yii::$app->request->post()) && $users = $model->saveTextArea()) {
        Yii::$app->session->setFlash('info', print_r($users));
    } 

    return $this->render('import',[
        'model'=>$model,
    ]);
}

型号:

public function attributeLabels()
{
    return [
        'id' => Yii::t('backend', 'ID'),
        'first_name' => Yii::t('backend', 'First Name'),
        'last_name' => Yii::t('backend', 'Last Name'),
        'user_id' => Yii::t('backend', 'User ID'),
        'student_number' => Yii::t('backend', 'Student Number'),
        'national_id' => Yii::t('backend', 'National ID'),
        'average' => Yii::t('backend', 'Average'),
        'vip' => Yii::t('backend', 'Vip'),
        'location_id' => Yii::t('backend', 'Location ID'),
    ];
}
public function SaveTextArea()
{
    $users = explode(";", $this->first_name);
    foreach ($users as $user){
        list($first_name,$last_name,$student_number,$national_id) = explode(";", $user);
    }
    return $ali;
}

0 个答案:

没有答案