0

私は小さなアプリケーションをやっています。そのために sles と store のようなテーブルを 2 つ持っています 販売テーブルは次のようになります

============
  Sales
============
id
store_id


Stores
=============
id
store_name
store_location
store_code
description

両方のテーブルのモデルと CRUD を実行しました。店舗テーブルに、テーブルに従っていくつかの値を入力しました。販売コントローラーで、販売と店舗の両方をレンダリングしました。だからここで私のアクションはこのように作成します

public function actionCreate()
  {
    $model=new Sales;
    $stores = new Stores;

    // Uncomment the following line if AJAX validation is needed
    // $this->performAjaxValidation($model);

    if(isset($_POST['Sales'], $_POST['Stores']))
    {
      $model->attributes=$_POST['Sales'];
      $stores->attributes=$_POST['Stores'];
      $valid = $model->validate();
      $valid = $stores->validate();
      if($valid)
      {
        $stores->save(false);
        $model->store_id = $stores->getPrimaryKey();
        $model->save(false);
        $this->redirect(array('view','id'=>$model->id));
      }
    }

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

そしてsales(_form.php)ではこのようなものです

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

  <div class="row">
    <?php echo $form->labelEx($stores,'store_location'); ?>
    <?php echo $form->textField($stores,'store_location',array('size'=>45,'maxlength'=>45)); ?>
    <?php echo $form->error($stores,'store_location'); ?>
  </div>

  <div class="row">
    <?php echo $form->labelEx($stores,'store_code'); ?>
    <?php echo $form->textField($stores,'store_code',array('size'=>45,'maxlength'=>45)); ?>
    <?php echo $form->error($stores,'store_code'); ?>
  </div>

ここで販売を行っているときに、キーを入力して 1 つの店名を入力するstores namesstore_location、関連する店名が表示され始め、store_code自動入力されるようにしたいと考えています。誰かが親切にこれを行う方法を教えてもらえますか? どんな助けや提案もかなりのものです。どうもありがとう。

編集 これでオートコンプリートできるフィールドは 1 つだけですしかし、他のすべての関連フィールドもこれでオートコンプリートする必要があります。

4

1 に答える 1