3

私はyii フレームワークの初心者です。現在、私は2つのテーブルを持っています.1つsalesstores Sales tableこのように見えます.

==============
      sales
  ==============
  id
  store_id

store tableこのように見えます

 ==============
      Stores
  ==============
  id
  store_name
  store_location

販売ビュー フォーム (_form.php) で、販売と店舗の両方をレンダリングしました。セールスコントローラーでは、アクション作成のコードは次のようになります

  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,
    ));
  }

ドロップダウンリストですべての店舗名を取得するには、次のようなコードを作成しました

    <div class="row">
    <?php echo $form->labelEx($stores,'store_name'); ?>
    <?php echo $form->dropDownList($stores,'store_name', CHtml::listData(Stores::model()->findAll(), 'store_name', 'store_name'), array('empty'=>'--Select--')) ?>
    <?php echo $form->error($stores,'store_name'); ?>
  </div>

しかし、ここでは cjuiautocomplete フィールドを使用して、誰かが任意のキーを押すと、候補のストア名が表示されるようにします。そのために、私はこのリンクから来ました

ドキュメントと同じように、保護/拡張ディレクトリの下にEAutoCompleteAction.phpを作成しました次に、セールスコントローラーでこのようなコントローラーコードを作成しました

 public function actions()
    {
      return array(
        'aclist'=>array(
          'class'=>'application.extensions.EAutoCompleteAction',
          'model'=>'Stores', //My model's class name
          'attribute'=>'store_name', //The attribute of the model i will search
        ),
      );
    }

そして、セールス(_form.php)のビューファイルで、私はこのようなコードを作りました

    <div class="row">
    <?php echo $form->labelEx($stores,'store_name'); ?>
    <?php 
  $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
      'attribute'=>'store_name',
        'model'=>$stores,
        'sourceUrl'=>array('stores/store_name'),
        'name'=>'store_name',
        'options'=>array(
          'minLength'=>'3',
        ),
        'htmlOptions'=>array(
          'size'=>45,
          'maxlength'=>45,
        ),
  )); ?>

結局、キーワードで検索していると、firebug のコンソール パネルに 404 エラーが表示されます。firebug で要求された検索 URL は次のようになりました (ads はストア名フィールドの私の検索クエリでした)

http://localhost/WebApp/index.php?r=stores/store_name&term=ads

誰か助けを求めてここにいますか?

4

1 に答える 1