Php 表单文本值不传递为模型插入输入的值

Php 表单文本值不传递为模型插入输入的值,php,model-view-controller,Php,Model View Controller,我有一个MYSQL中的表模型和一个用户可以用来输入特定值的表单。我对表单将这些textinput值传递到模型以进行插入有问题。如果我在模型中删除所需的规则,它将在表中输入一行,但包含所有空值 这是你的电话号码 型号: class QRCodes extends \CActiveRecord { public static function model($className = __CLASS__) { return parent::model($className);

我有一个MYSQL中的表模型和一个用户可以用来输入特定值的表单。我对表单将这些textinput值传递到模型以进行插入有问题。如果我在模型中删除所需的规则,它将在表中输入一行,但包含所有空值

这是你的电话号码

型号

class QRCodes extends \CActiveRecord {

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public function tableName() {
        return 'qr_codes';
    }

    public function rules() {
        return array(
            array('qr_code_name,target_url,assigned_url','required'),
            //array('enabled,site_id,user_id','numerical', 'integerOnly' => true),
            array('qr_code_name,target_url,assigned_url,qr_comment','length','max'=>255),
            array('qr_code_id,qr_code_name,target_url,assigned_url,qr_image,qr_file, qr_comment,enabled,site_id,user_id','safe','on'=>'search'),    
        );
    }

    public function relations() {
        return array();
    }

    public function attributeLabels() {
      return array(
        'qr_code_id' => 'QR ID',
        'qr_code_name' => 'QR Name',
        'target_url' => 'Target URL',
        'assigned_url' => 'Assigned URL',
        'qr_image' => 'QR Image',
        'qr_file' => 'QR File',
        'qr_comment' => 'QR Comment',
        'create_date' => 'Create Date',
        'mod_date' => 'Mod Date',
        'enabled' => 'Enabled',
        'site_id' => 'Site ID',
        'user_id' => 'User ID',
      );
    }

    public function search() {
      $criteria = new \CDbCriteria;

      $criteria->compare('qr_code_id', $this->qr_code_id);
      $criteria->compare('qr_code_name', $this->qr_code_name,true);
      $criteria->compare('target_url', $this->target_url,true);
      $criteria->compare('assigned_url', $this->assigned_url, true);
      $criteria->compare('qr_image', $this->qr_image);
      $criteria->compare('qr_file', $this->qr_file);
      $criteria->compare('qr_comment', $this->qr_comment);
      $criteria->compare('create_date', $this->create_date);
      $criteria->compare('mod_date', $this->mod_date);
      $criteria->compare('enabled', $this->enabled);
      $criteria->compare('site_id', $this->site_id);
      $criteria->compare('user_id', $this->user_id);

      return new \CActiveDataProvider($this,array(
          'criteria' => $criteria,
      ));
    }
}
查看

use src\models\web_data\QRCodes;
/* @var $this DefaultController */
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id' => 'qrcodes-form',
    'enableAjaxValidation' => false,
    'type' => 'horizontal'
));

?>

<p class="help-block">
    Fields with <span class="required">*</span> are required.
</p>

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

<?php echo $form->textFieldRow($model, 'qr_code_name', array('class' => 'span5', 'maxlength' => 255, 'readonly' => !$model->isNewRecord)); ?>

<?php echo $form->textFieldRow($model, 'target_url', array('class' => 'span5', 'maxlength' => 255,'readonly' => !$model->isNewRecord)); ?>

<?php echo $form->textFieldRow($model, 'assigned_url', array('class' => 'span5', 'maxlength' => 255,'readonly' => !$model->isNewRecord)); ?>

<?php echo $form->textFieldRow($model, 'qr_comment', array('class' => 'span5', 'maxlength' => 255,'readonly' => !$model->isNewRecord)); ?>

<div class="form-actions">
  <?php
  $this->widget('bootstrap.widgets.TbButton', array(
      'buttonType' => 'submit',
      'type' => 'primary',
      'label' => $model->isNewRecord ? 'Create' : 'Update',
  ));
  ?>
</div>

<?php
print_r($model->getErrors());
$this->endWidget();
?>
使用src\models\web\u data\QRCodes;
/*@var$this DefaultController*/
$form=$this->beginWidget('bootstrap.widgets.TbActiveForm',数组(
'id'=>'qrcodes form',
'enableAjaxValidation'=>false,
'类型'=>'水平'
));
?>

带*的字段是必填字段。

控制器

<?php

namespace admin\modules\coredataadministration\controllers;

use admin\modules\coredataadministration\components\Controller;
use src\models\web_data\QRCodes;

class QRController extends Controller {

    /**
     * (non-PHPdoc)
     * @see CController::filters()
     */
    public function filters() {
        return parent::filters();
    }

    /**
   * (non-PHPdoc)
   * @see \components\admin\Controller::beforeAction()
   */
    public function beforeAction($action) {
        return parent::beforeAction($action);
    }

    public function actionIndex() {
        $this->render('index');
    }

    public function actionCreate() {
      $model = new QRCodes('CRUD');

      if ($model->save()) {
          $this->redirect($this->createUrl('index'));
      }

      $this->render('create',array('model' => $model));
    }
}

controller dude在哪里?我看不到任何与向表中插入数据相关的代码。我认为这些代码与YII框架相关。是吗?@NanaPartykar。我没有发布控制器,因为我认为这不是问题所在。我现在添加它。在控制器中使用此代码并告诉我输出
公共函数actionCreate(){$model=new QRCodes();if($model->load(Yii::$app->request->post()){$post=Yii::$app->request->post('QRCodes');echo$post['qr_code_name'];die;}$this->render('create',array('model'=>$model))}
@NanaPartykar,使用该代码会出现500错误。包括(C:\Program Files(x86)\Zend\Apache2\htdocs\webapps\src\config/./../admin\modules\coredataadministration\controllers\Yii.php)[]:未能打开流:没有此类文件或目录