我只是新手。现在我有两张桌子
一个用于sales另一个用于stores
Sales table看起来像这样

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

store table看起来像这样
 ==============
      Stores
  ==============
  id
  store_name
  store_location

现在在sales视图表单(_form.php)中,我已经呈现了sales和stores。
在sales controller中,action create的代码如下
  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>

但这里我需要cguiautocomplete字段,这样当有人按下任何键时,它就会开始显示suggesions stores的名称。为此我刚刚通过了yii framework
就像我在protected/extension目录下创建的eautocompleteaction.php文档一样
然后我在Sales controller中做了这样的控制器代码
 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
        ),
      );
    }

在查看sales文件(_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是我在store name字段中的搜索查询)
http://localhost/WebApp/index.php?r=stores/store_name&term=ads

有人来帮忙吗?

最佳答案

您忘记将操作名称从sampleaclist更改为store_name

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

关于php - Yii框架CJUIautocomplete显示错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17653753/

10-13 03:19